请问一下关于一个 oracle 的语法问题

2020-10-20 17:43:29 +08:00
 18870715400
# 原来是因为原先的字段太长, 使用了 declare 语法, 

declare
  val1 number := ‘很长的字符串’;
begin
  select * from WARNING_INFO where SEQ_ID = :val1;
end;

# 但是之后又报了一个 并非所有变量已经绑定, 那么应该如何解决呢
1502 次点击
所在节点    Python
3 条回复
krixaar
2020-10-21 08:04:27 +08:00
直接 prepare 这个 select,然后 execute 的时候把 val1 传进去。
18870715400
2020-10-21 10:17:55 +08:00
declare
val1 number := ‘很长的字符串’;
begin
select * from WARNING_INFO where SEQ_ID = val1;
end;
/

正确的语法
18870715400
2020-10-23 15:22:54 +08:00
sql = """declare
val1 number := ‘很长的字符串’;
begin
select * from WARNING_INFO where SEQ_ID = val1;
end;
"""
cursor.execute(sql)
使用 cx_Oracle 执行的时候不需要有斜号,另外 clob 字段内容不要有单引号或者双引号,不然会有错误

这是一个专为移动设备优化的页面(即为了让你能够在 Google 搜索结果里秒开这个页面),如果你希望参与 V2EX 社区的讨论,你可以继续到 V2EX 上打开本讨论主题的完整版本。

https://www.v2ex.com/t/716802

V2EX 是创意工作者们的社区,是一个分享自己正在做的有趣事物、交流想法,可以遇见新朋友甚至新机会的地方。

V2EX is a community of developers, designers and creative people.

© 2021 V2EX