[英]Change <class 'cx_Oracle.Cursor'> to list or dict in python
I am working on a code to fetch data from a server and then plot two column of data in python. 我正在研究从服务器获取数据,然后在python中绘制两列数据的代码。 I am using cx_Oracle library and I could fetch data.
我正在使用cx_Oracle库,可以获取数据。
But as I checked type of fetched data is class 'cx_Oracle.Cursor'
. 但是当我检查获取的数据的类型时,
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 ? 我想绘制sdate与ID_73393960的关系,但是如何绘制?
In your code "c" is the cursor... it is NOT your data. 在您的代码中,“ c”是光标……不是您的数据。 you need to pull the data out using a fetch command.
您需要使用fetch命令提取数据。 This is an example from the cx_oracle tutorial using fetchone()-
这是cx_oracle教程中使用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) https://github.com/oracle/python-cx_Oracle/tree/master/samples/tutorial (尝试使用本教程来学习游标对象上的其余方法)
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)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.