python中非法变量名 | 您所在的位置:网站首页 › python非法变量命名 › python中非法变量名 |
因为cx_Oracle试图绑定giftcardnbr和giftcard_amt不存在的绑定变量的第一个查询不起作用。 如果我在调用一切绑定变量的正确数字是罚款: >>> import cx_Oracle >>> DB = cx_Oracle.connect('ben/****@s1/s1') >>> cur = DB.cursor() >>> SQL = "select * from dual where 1 = :a" >>> cur.execute(SQL, {'a' : 1}).fetchall() [('X',)] 如果我尝试一个不存在的变量绑定则无法用同样的错误: >>> cur.execute(SQL, {'a' : 1, 'b' : 2}).fetchall() Traceback (most recent call last): File "", line 1, in cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number 你的第二个电话失败,因为'2016/10/16'不是日期,它是一个字符串(请参阅我以前的回答Comparing Dates in Oracle SQL)。 如果我们构建一个日期,然后用它来比较的日期一切都很好: >>> import datetime >>> my_date = datetime.datetime(year=2016, month=10, day=16) >>> my_date datetime.datetime(2016, 10, 16, 0, 0) >>> SQL = "select * from dual where date '2016-01-01' = :calendar" >>> cur.execute(SQL, {'calendar' : my_date }).fetchall() [] |
CopyRight 2018-2019 实验室设备网 版权所有 |