V2EX = way to explore
V2EX 是一个关于分享和探索的地方
Sign Up Now
For Existing Member  Sign In
推荐学习书目
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 · Oct 20, 2020 · 1960 views
    This topic created in 2023 days ago, the information mentioned may be changed or developed.
    # 原来是因为原先的字段太长, 使用了 declare 语法, 
    
    declare
      val1 number := ‘很长的字符串’;
    begin
      select * from WARNING_INFO where SEQ_ID = :val1;
    end;
    
    # 但是之后又报了一个 并非所有变量已经绑定, 那么应该如何解决呢
    
    3 replies    2020-10-23 15:22:54 +08:00
    krixaar
        1
    krixaar  
       Oct 21, 2020
    直接 prepare 这个 select,然后 execute 的时候把 val1 传进去。
    18870715400
        2
    18870715400  
    OP
       Oct 21, 2020
    declare
    val1 number := ‘很长的字符串’;
    begin
    select * from WARNING_INFO where SEQ_ID = val1;
    end;
    /

    正确的语法
    18870715400
        3
    18870715400  
    OP
       Oct 23, 2020
    sql = """declare
    val1 number := ‘很长的字符串’;
    begin
    select * from WARNING_INFO where SEQ_ID = val1;
    end;
    """
    cursor.execute(sql)
    使用 cx_Oracle 执行的时候不需要有斜号,另外 clob 字段内容不要有单引号或者双引号,不然会有错误
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   2792 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 39ms · UTC 12:48 · PVG 20:48 · LAX 05:48 · JFK 08:48
    ♥ Do have faith in what you're doing.