python - Python 3.7.0 c.execute(v_sql,[Part_no, Rev_no]) 无法识别我的变量
问题描述
我一直在尝试使用 Oracle_CX 库从 Oracle DB 中检索数据。但是,当我对 c.execute(v_sql,['02502-9001-12','SS']) 进行硬编码时,它会返回正确的数据。但是,当我必须将变量传递给函数时 c.execute(v_sql,[Part_No,Rev_no]) 无法识别输出为(无)的值
我试图做的是仅当我对数据进行硬编码时才将值传递给 Part_No 和 Rev_no,这样我才能接收到正确的数据。我什至在 c.execute() 发生之前打印,看看是否打印了 Part_No 和 Rev_no 并且它发生了。实际错误是我没有收到正确的数据(无),我想收到 AAAW07AAFAAF5/PAAq。看起来 def why_(Part_no, Rev_no) 的值没有填充到 c.execute(v_sql,[Part_No,Rev_no])
c.execute(v_sql,[Part_No,Rev_no])
c.execute(v_sql,['02502-9001-12','SS'])
import cx_Oracle
import os
def why__(Part_No, Rev_no):
dsn_tns = cx_Oracle.makedsn('XXXXX', 'XXXX', service_name='XXXXX')
conn = cx_Oracle.connect(user=r'XXXX', password='XXXX', dsn=dsn_tns)
c = conn.cursor()
#u_sql =('SELECT PART_REV_CFP.GET_OBJKEY(:Part_No,:Rev_no) from dual')
v_sql =('SELECT PART_REV_CFP.GET_OBJKEY(:Part_No,:Rev_no) from dual')
print(Part_No)
print(Rev_no)
c.execute(v_sql,[Part_No,Rev_no])
#c.execute(v_sql,['02502-9001-12','SS'])
R = c.fetchone()
print('before the loop')
i=0
for row in R:
print('inside the loop')
i+=1
print(i)
print(str(row))
print('after the loop')
conn.close()
return row
Part_No = input("Enter the obs part num: ")
Rev_no = input("Enter the obs part rev: ")
why__(Part_No,Rev_no)
print('outside of the method')
print(why__(Part_No,Rev_no))
OutPut when c.execute(v_sql,[Part_No,Rev_no]) --IN other words no hard coding the values of Part_no and Rev_no
Enter the obsolete part number: 02502-9001-12
Enter the obsolete part revision: ss
before the loop
inside the loop
1
(None,)
after the loop
***Repl Closed***
Output when c.execute(v_sql,['02502-9001-12','SS'])
Enter the obsolete part number: 02502-9001-12
Enter the obsolete part revision: ss
02502-9001-12
ss
before the loop
inside the loop
1
AAAW07AAFAAF5/PAAq
after the loop
outside of the method
02502-9001-12
ss
before the loop
inside the loop
1
AAAW07AAFAAF5/PAAq
after the loop
AAAW07AAFAAF5/PAAq
***Repl Closed***
解决方案
推荐阅读
- java - Spring JDBC 中的错误 Sql 语法异常
- sql - 是否可以将 SSIS 包中使用的文件记录到自定义执行表中?
- javascript - 强制外部链接(来自我的网站)在该设备的默认浏览器中的新选项卡中打开?
- python-3.x - lru_cache 为所有类实例保存
- elasticsearch - Elasticsearch 在脚本字段中访问 params['_source'] 时返回 null_pointer_exception
- php - MySqlBuilder::defaultStringLength()
- rpm - 从 RPM DB、BerkeleyDB 获取已安装的软件包
- azure-devops - 部署到 Visual Studio App Center 的二进制文件路径
- sublimetext3 - SublimeText 不打开多个文件
- php - 使用带有 php 页面的 Android 在 MySQL 中添加数据