【发布时间】:2022-01-12 01:15:03
【问题描述】:
我有一个 run_dt 在创建表时产生问题,列数据类型会自行更改为 Char。
print(execution_dt)
2020-10-05 14:24:25.352317
run_dt= execution_dt.date()
print(run_dt)
2020-10-05
run_dt=str(run_dt)
print(run_dt)
2020-10-05
type(run_dt)
<class 'str'>
我有 Oracle db 作为后端和 python 来编写脚本。
cursor.execute(f'''create table taxes
select age,
name,
'{run_dt}' as max_upload_date,
from Employee a left outer join code cd on (s.emp_id = cd.code)
and s.transaction_date = {repr(run_dt)}
''')
如果我执行上面的 python 代码,它会创建一个表格 tax,但是 max_upload_date - column datatype 会自动变成 - Char。
如果我按以下方式应用 to_date 函数:
to_date('{run_dt}') as max_upload_date,
我收到以下错误:
错误 - cx_Oracle.DatabaseError: ORA-01861: 文字与格式字符串不匹配
请帮忙。提前致谢。
【问题讨论】:
标签: python sql python-3.x oracle-sqldeveloper cx-oracle