前端之家收集整理的这篇文章主要介绍了
cx_Oracle 查询 传参,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
#coding=utf-8
import threading
import time
import cx_Oracle
from pprint import pprint
import csv
table_name = "dbtest.csv"
f = open(table_name + ".csv","w")
conn = cx_Oracle.connect('tlcbuser/tlcbuser@20.5.101.31/tlyy')
cursor = conn.cursor()
def query01():
aa=10
# cursor.execute("SELECT * FROM TEST100 WHERE ID = %s",[aa])
cursor.prepare("""SELECT * FROM TEST100 WHERE ID=:id""")
cursor.execute(None,{'id':aa})
row = cursor.fetchall()
return row
a=query01()
print a
#coding=utf-8
import threading
import time
import cx_Oracle
from pprint import pprint
import csv
table_name = "dbtest.csv"
f = open(table_name + ".csv",{'id':aa})
row = cursor.fetchall()
return row
a=query01()
print a
C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/a1.py
[(10,'10boobook10','10aaaaaaaaaaaa10','10bbbbbbbbbbbbbbbbb10'),(10,'10sssssssss10','tlcb','tlcb')]
Process finished with exit code 0
#coding=utf-8
import threading
import time
import cx_Oracle
from pprint import pprint
import csv
table_name = "dbtest.csv"
f = open(table_name + ".csv","w")
conn = cx_Oracle.connect('tlcbuser/tlcbuser@20.5.101.31/tlyy')
cursor = conn.cursor()
def query01():
aa=10
bb='tlcb'
# cursor.execute("SELECT * FROM TEST100 WHERE ID = %s",[aa])
cursor.prepare("""SELECT * FROM TEST100 WHERE ID=:cc and A2=:dd""")
cursor.execute(None,{'cc':aa,'dd':bb})
row = cursor.fetchall()
return row
a=query01()
print a
C:\Python27\python.exe C:/Users/tlcb/PycharmProjects/untitled/a1.py
[(10,'tlcb')]
Process finished with exit code 0
原文链接:https://www.f2er.com/oracle/206245.html