代码之家  ›  专栏  ›  技术社区  ›  VinceP

在sqlalchemy/cx\u oracle中使用绑定参数创建表失败

  •  0
  • VinceP  · 技术社区  · 7 年前

    from sqlalchemy.sql import text
    from sqlalchemy import create_engine
    
    con = create_engine(\\..)
    s = text("""create table test_table as select * from dual where 1 = 1 """)
    con.execute(s)
    

    但是,如果我使用绑定参数:

    s = text("""create table test_table as select * from dual where 1 = :a """)
    con.execute(s, a = 1)
    

    它因错误而失败 DatabaseError: (cx_Oracle.DatabaseError) ORA-01036: illegal variable name/number .

    s = text("""select * from dual where 1 = :a """)
    con.execute(s, a = 1).fetchall()
    #[('X',)]
    

    1 回复  |  直到 7 年前
        1
  •  2
  •   Anthony Tuininga    7 年前

    DDL语句中不允许使用绑定变量。这就是为什么它在一个简单的查询中可以像预期的那样工作,但一旦有了create table语句,它就会失败。不幸的是,您将不得不在没有任何绑定变量的情况下编写DDL语句!