Query executed in Python does not return information from my Oracle database

1

The problem is that I'm doing some queries to the oracle 9 database from my python 2.7 script with the help of cx_oracle but when printing the cursor values it does not return information which IF IT EXISTS in the database.

I have tried placing the values of each field in the where with single quotes, without single quotes, with = to_char (##) and nothing that returns the information.

It should be noted that all the columns in the table are Varchar (2) and when doing the query in the manager if you return information .

Next the code

# -*- coding: cp1252 -*-
import cx_Oracle

ip = 'xxx.xxx.xxx.xxx'
port = xxxx
SID = 'xxxxx'
dsn_tns = cx_Oracle.makedsn(ip, port, SID)
conector = cx_Oracle.connect('USER', 'PASS', dsn_tns)

cursor = conector.cursor()  #cursor


#AQUI EL QUERY
querystring ="""SELECT * FROM NOMBRE_TABLA 
where cia='1' 
and scia='2' 
and ccosto='1500' 
and line='00'
and fn='00'
and cta='12345678' """


cursor.execute(querystring)

cursor.fetchmany()

for c in cursor:
    print c 

and I do not have information in the Python Shell.

    
asked by Javier 25.05.2017 в 17:12
source

1 answer

0

You have probably exhausted the records returned when doing cursor.fetchmany() , so you do not see anything else later.

You could have done it like this:

for row in cursor.fetchmany():
    print row

If the result had many lines, you would have to page the output:

while True:
    for row in cursor.fetchmany():
        print row
    else:
        break

But, in general, the database python connectors are quite optimized and they know how to control the cursors of the database. Let them do their work and do not worry about anything other than iterating with the cursor:

#cursor.fetchmany()

for row in cursor:
    print row
    
answered by 25.05.2017 в 18:19