I have a query and that query only throws me a record and when I optengo I ask you to throw me the value that is in the position [0]
for a in datos_estados:
tabla_datos = [a["estado"], a["seccion"], 'Teorico']
for vuelta in range(mes_inicio, 13):
query = '''
SELECT NVL(TRIM(TO_CHAR(SUM(TOTAL),'999,999,999,999,999.00')),0) "teorico"
FROM CL_RP_COBRANZA_TNR_TEORICO
WHERE TO_CHAR(FECHA_VENCIMIENTO,'MM/RRRR')='{0}/{1}' AND
ESTADO='{2}' AND
SECCION='{3}'
GROUP BY ESTADO,
SECCION
ORDER BY ESTADO, SECCION'''.format(vuelta, ano_inicio,a["estado"],a["seccion"])
#print query
datos_teorico = consulta_asociativa(query, conexion['cursor'])[0]
tabla_datos.append(datos_teorico["teorico"])
tabla_datos.append(" ")
In the query there is no record in the DB, for that reason it is why I can not find the position [0], but how can I avoid not getting an error?