在存储过程中截断表 [英] Truncating a table in a stored procedure

查看:81
本文介绍了在存储过程中截断表的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在Oracle shell中运行以下命令时,它工作正常

When I run the following in an Oracle shell it works fine

truncate table table_name

但是当我尝试将其放入存储过程中

But when I try to put it in a stored procedure

CREATE OR REPLACE PROCEDURE test IS
BEGIN
    truncate table table_name;
END test;
/

失败

ERROR line 3, col 14, ending_line 3, ending_col 18, Found 'table', Expecting:  @   ROW  or   (   or   .   or   ;   :=

为什么?

推荐答案

Oracle PL/SQL中的所有DDL语句均应在该语句之前使用立即执行".因此,您应该使用:

All DDL statements in Oracle PL/SQL should use Execute Immediate before the statement. Hence you should use:

execute immediate 'truncate table schema.tablename';

这篇关于在存储过程中截断表的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆