一个Tuple转换为List的问题
使用Cx_Oracle链接数据库,然后从数据库查询数据,Cx_Oracle返回的是Tuple值,想把Tuple转换为List的时候一直报错;
import sys
import cx_Oracle
ora_ip="10.1.1.244"
ora_port="1522"
SERVICE_NAME="ora10g"
ora_dsn=cx_Oracle.makedsn(ora_ip,ora_port,SERVICE_NAME)
connection = cx_Oracle.connect("username","passwd",ora_dsn)
cursor = connection.cursor()
list_len =''
list =''
re_num=''
result=()
r_temp =''
lo_num=0
t_result =[]
ex_sql="select distinct id from sq_id"
try:
list=cursor.execute(ex_sql)
###cursor.execute(u"commit")
result=list.fetchall()
connection.close()
for r in result:
t_result.append(list(r))
except cx_Oracle.DatabaseError, exc:
error, = exc.args
print >> sys.stderr, "Oracle-Error-Code:", error.code
print >> sys.stderr, "Oracle-Error-Message:", error.message
最后总是报 t_result.append(list(r))
TypeError: 'OracleCursor' object is not callable。
有没大侠遇到过这样的问题?为什么不能把Tuple转换为List呢?
import sys
import cx_Oracle
ora_ip="10.1.1.244"
ora_port="1522"
SERVICE_NAME="ora10g"
ora_dsn=cx_Oracle.makedsn(ora_ip,ora_port,SERVICE_NAME)
connection = cx_Oracle.connect("username","passwd",ora_dsn)
cursor = connection.cursor()
list_len =''
list =''
re_num=''
result=()
r_temp =''
lo_num=0
t_result =[]
ex_sql="select distinct id from sq_id"
try:
list=cursor.execute(ex_sql)
###cursor.execute(u"commit")
result=list.fetchall()
connection.close()
for r in result:
t_result.append(list(r))
except cx_Oracle.DatabaseError, exc:
error, = exc.args
print >> sys.stderr, "Oracle-Error-Code:", error.code
print >> sys.stderr, "Oracle-Error-Message:", error.message
最后总是报 t_result.append(list(r))
TypeError: 'OracleCursor' object is not callable。
有没大侠遇到过这样的问题?为什么不能把Tuple转换为List呢?
作者: zaibian 发布时间: 2011-05-24
回复 zaibian
cursor.execute(ex_sql)
result=cursor.fetchall()
QUOTE:
try:
list=cursor.execute(ex_sql)
###cursor.execute(u"commit")
result=list.fetchall()
connection.close()
zaibian 发表于 2011-05-24 16:37
list=cursor.execute(ex_sql)
###cursor.execute(u"commit")
result=list.fetchall()
connection.close()
zaibian 发表于 2011-05-24 16:37
cursor.execute(ex_sql)
result=cursor.fetchall()
作者: 106033177 发布时间: 2011-05-24