truncate table需要你有delete any table的权限。你把你的存储过程代码贴出来看看SQL> create or replace procedure p_truncatetable 2 as 3 begin 4 execute immediate 'truncate table ttt'; 5 end; 6 /过程已创建。SQL> select * from ttt; ID NAME ---------- ---------- 1 zxfSQL> exec p_truncatetable;PL/SQL 过程已成功完成。SQL> select * from ttt;未选定行SQL>
用户的权限不够,只有DBA权限是不行的。只有DBA权限时在Sql*PLus中可以查到其他用户的表,在包、过程中是找不到的。需要单独授权,或Grant Dba, all privileges to 用户。
试过了不行,一样的错误。 这个用户有DBA权限。
只有dba权限是不行的,还需要delete any table,insert any table,update any table, select any table权限才可以在包、过程中使用其他用户的表否则只能在sql*plus中用。 也可以连接到表所在的用户单独将表的delete、update、insert、select的权限授权给其他用户。
如果不能用可能是你没权限
2 as
3 begin
4 execute immediate 'truncate table ttt';
5 end;
6 /过程已创建。SQL> select * from ttt; ID NAME
---------- ----------
1 zxfSQL> exec p_truncatetable;PL/SQL 过程已成功完成。SQL> select * from ttt;未选定行SQL>
ORA-06550: 第 1 行, 第 7 列:
PLS-00905: 对象 SRAPP_HZSQ.TT_PRO 无效
ORA-06550: 第 1 行, 第 7 列:
PL/SQL: Statement ignored
如果是先删表,后建表的方法,在效率上是否比其他(truncate、delete)要好?
如果你的表关联的对象太多,就用truncate
create or replace procedure tt_pro
as
begin
truncate table t1;
end;
必须使用
execute immediate 'truncate table t1';
这个用户有DBA权限。
只有dba权限是不行的,还需要delete any table,insert any table,update any table, select any table权限才可以在包、过程中使用其他用户的表否则只能在sql*plus中用。
也可以连接到表所在的用户单独将表的delete、update、insert、select的权限授权给其他用户。
如果用truncate也存在潜在的问题。如果你在truncate之后插入数据,这是数据库荡了·那么你用户就看不见数据了,
而你用delete 则会回滚···
表中数据有500W,用delete的话是不是慢了点?有没有其他更好的办法呢?