截断Oracle PL / SQL块中的多个表失败

问题描述

运行以下脚本:

select * from <Table Name> where first_name like q'[%'%]';

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

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()

解决方法

您可以使用:

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无关。