0

I am working on a code to fetch data from a server and then plot two column of data in python. I am using cx_Oracle library and I could fetch data.

But as I checked type of fetched data is class 'cx_Oracle.Cursor'.

How can I change data type to list or dictionary :

import cx_Oracle

conn_str = u'user/pass@IP1:1521/STAT4P'
conn = cx_Oracle.connect(conn_str)
c = conn.cursor()
sql='''select ne,sdate,slot_no,subrack_no,ID_73393960 as HIII,ID_73410486 from Huawei_wcdma.UDSP60 where ne=:name'''

# c.execute(u'select ne,sdate,slot_no,subrack_no,ID_73393960,ID_73410486 from Huawei_wcdma.UDSP60')
c.execute(sql,name="AQRNCH01")
print(type(c))

I want to plot sdate vs. ID_73393960 , but how ?

1 Answer 1

2

In your code "c" is the cursor... it is NOT your data. you need to pull the data out using a fetch command. This is an example from the cx_oracle tutorial using fetchone()-

https://github.com/oracle/python-cx_Oracle/tree/master/samples/tutorial (Try the tutorial to learn the rest of the methods on the cursor object)

import cx_Oracle

con = cx_Oracle.connect("pythonhol", "welcome", "localhost/orclpdb")
cur = con.cursor()

cur.execute("select * from dept order by deptno")
row = cur.fetchone()
print(row)

row = cur.fetchone()
print(row)
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks Paul for your reply, but my data is a matrix of 1000*10,000 data stats and using this, I will have only one rpw of data , am I right ? how to fetch all data in a column ?
Does a Cursor work as an iterator? It's supposed to be a PEP 249/DB-API2 implementation. Not that next(cur) is any clearer than cur.fetchone(), but, e.g., a generator expression over cur is a lot clearer than a generator expression over iter(cur.fetchone, None).
I was saying that while my answer is the specific error you asked about, you are going to need to read the docs to answer the next three problems you are going to have.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.