V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
Learn Python the Hard Way
Python Sites
PyPI - Python Package Index
http://diveintopython.org/toc/index.html
Pocoo
值得关注的项目
PyPy
Celery
Jinja2
Read the Docs
gevent
pyenv
virtualenv
Stackless Python
Beautiful Soup
结巴中文分词
Green Unicorn
Sentry
Shovel
Pyflakes
pytest
Python 编程
pep8 Checker
Styles
PEP 8
Google Python Style Guide
Code Style from The Hitchhiker's Guide
18870715400
V2EX  ›  Python

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

  •  
  •   18870715400 · 2020-10-20 17:43:29 +08:00 · 1493 次点击
    这是一个创建于 1274 天前的主题,其中的信息可能已经有所发展或是发生改变。
    # 原来是因为原先的字段太长, 使用了 declare 语法, 
    
    declare
      val1 number := ‘很长的字符串’;
    begin
      select * from WARNING_INFO where SEQ_ID = :val1;
    end;
    
    # 但是之后又报了一个 并非所有变量已经绑定, 那么应该如何解决呢
    
    3 条回复    2020-10-23 15:22:54 +08:00
    krixaar
        1
    krixaar  
       2020-10-21 08:04:27 +08:00
    直接 prepare 这个 select,然后 execute 的时候把 val1 传进去。
    18870715400
        2
    18870715400  
    OP
       2020-10-21 10:17:55 +08:00
    declare
    val1 number := ‘很长的字符串’;
    begin
    select * from WARNING_INFO where SEQ_ID = val1;
    end;
    /

    正确的语法
    18870715400
        3
    18870715400  
    OP
       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 字段内容不要有单引号或者双引号,不然会有错误
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   3300 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 28ms · UTC 14:11 · PVG 22:11 · LAX 07:11 · JFK 10:11
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.