oracle 日期绑定变量,Oracle将变量绑定到\u date参数E

我正在编写使用Python脚本执行SQL(Oracle)语句的代码,如下所示:

PYTHON:with open(os.path.join(WORKING_PATH, "sql", "fetchCalendar.sql"), 'r') as

fetch_date = fetch.read()

#(Some other code)

CD = timestamp_tostring(ACTUALDATE)

print("CD:", CD)

cnnSB.cursor.execute(fetch_date, CD)

fetchCalendar.sql

^{pr2}$

当我尝试使用以下值运行它时,将输出:CD: 30-AUG-18

Traceback (most recent call last): File "AHT_Init.py",

line 919, in

init_load(data, end_of_week, cur, 3) File "AHT_Init.py", line 644, in init_load

populate_rollup(modelid, test_data, train_data, rollup_cmd) File "AHT_Init.py", line 684, in populate_rollup

cnnSB.cursor.execute(fetch_date, CD) cx_Oracle.DatabaseError: ORA-01036: illegal variable name/number

(强调'ORA-01036:非法变量名称/编号')

当然,我尝试更改变量名,但没有成功。我尝试使用Oracle SQL Developer运行SQL代码(在提示时传入'01-JUN-18',包括单引号),但得到以下错误:ORA-01858: a non-numeric character was found where a numeric was

expected

01858. 00000 - "a non-numeric character was found where a numeric was expected"

*Cause: The input data to be converted using a date format model was

incorrect. The input data did not contain a number where a number was

required by the format model.

*Action: Fix the input data or the date format model to make sure the

elements match in number and type. Then retry the operation.

不过,当我用以下内容替换出有问题的行时:

^{3}$

代码按预期工作。

有谁能告诉我问题可能是什么,以及如何解决它吗?

非常感谢你!在

编辑:我知道在fetchCalendar.sql代码;这对于Python如何在这个上下文中与Oracle交互是必需的。出于测试目的,我在oraclesqldeveloper上尝试它时添加了一个分号,但是在为.SQL文件删除它时不会引起问题。在

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值