【问题标题】:Truncating multiple tables in a Oracle PL/SQL block fails截断 Oracle PL/SQL 块中的多个表失败
【发布时间】:2020-09-03 16:45:16
【问题描述】:

运行以下脚本:

import cx_Oracle

conn = cx_Oracle.connect(user = db_user, password = db_pwd, dsn = 'TULSA').
cur = conn.cursor()

sql = ("""  
        BEGIN
            truncate table shop_ord_temp;
            truncate table shop_ord_item_temp;
            truncate table shop_cust_temp;
        END;
    """)

cur.execute(sql)
cur.close()
conn.close()

运行此匿名块时收到此错误:

cx_Oracle.DatabaseError: ORA-06550: line 3, column 22:
PLS-00103: Encountered the symbol "TABLE" when expecting one of the following:

   := . ( @ % ;

【问题讨论】:

    标签: sql oracle plsql truncate


    【解决方案1】:

    你可以使用:

    sql = ("""  
            BEGIN
                execute immediate 'truncate table shop_ord_temp';
                execute immediate 'truncate table shop_ord_item_temp';
                execute immediate 'truncate table shop_cust_temp';
            END;
        """)
    

    这是一个 PL/SQL 功能,与 Python 无关。

    【讨论】:

      猜你喜欢
      • 2012-11-22
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多