查询语句
Test_oracle = {
"shengchan": {
"test_user": {"userName": "xxx", "pwd": "xxxx", "iP": "172.xx.xxx.xxx", "dbSID": "xxx"},
}
def search(test1,test2):
"""
查询语句
:param test1:参数化数据1
:param test2:参数化数据2
:return:
"""
userName = Test_oracle["shengchan"]["test_user"]["userName"]
pwd = Test_oracle["shengchan"]["test_user"]["pwd"]
iP = Test_oracle["shengchan"]["test_user"]["iP"]
dbSID = Test_oracle["shengchan"]["test_user"]["dbSID"]
conn = cx_Oracle.connect(userName + '/' + pwd + '@' + iP + ':xxxx/' + dbSID)
cur = conn.cursor()
named_params = { 'param1': test1,'param2':test2}
sql = "SELECT * FROM test_table WHERE test_TIME = :param1 AND TYPE = :param2"
cur.execute(sql,named_params)
data = cur.fetchall()
return data
修改语句
Test_oracle = {
"shengchan": {
"test_user": {"userName": "xxx", "pwd": "xxxx", "iP": "172.xx.xxx.xxx", "dbSID": "xxx"},
}
def update(test1,test2):
"""
修改语句
:param test1:参数化数据1
:param test2:参数化数据2
:return:
"""
userName = Test_oracle["shengchan"]["test_user"]["userName"]
pwd = Test_oracle["shengchan"]["test_user"]["pwd"]
iP = Test_oracle["shengchan"]["test_user"]["iP"]
dbSID = Test_oracle["shengchan"]["test_user"]["dbSID"]
conn = cx_Oracle.connect(userName + '/' + pwd + '@' + iP + ':xxxx/' + dbSID)
cur = conn.cursor()
named_params = { 'param1': test1,'param2':test2}
sql = "UPDATE Test_table SET test_data = :param1 WHERE TYPE = :param2"
cur.execute(sql,named_params)
conn.commit()
cur.close()
conn.close()