作爲我們構建過程和不斷髮展的數據庫的一部分,我試圖創建一個腳本,它將刪除用戶的所有表和序列。我不想重新創建用戶,因爲這需要比允許的更多權限。刪除Oracle中的所有用戶表/序列
我的腳本創建一個過程來刪除表/序列,執行過程,然後刪除過程。我是從sqlplus中執行文件:
的drop.sql:
create or replace procedure drop_all_cdi_tables
is
cur integer;
begin
cur:= dbms_sql.OPEN_CURSOR();
for t in (select table_name from user_tables) loop
execute immediate 'drop table ' ||t.table_name|| ' cascade constraints';
end loop;
dbms_sql.close_cursor(cur);
cur:= dbms_sql.OPEN_CURSOR();
for t in (select sequence_name from user_sequences) loop
execute immediate 'drop sequence ' ||t.sequence_name;
end loop;
dbms_sql.close_cursor(cur);
end;
/
execute drop_all_cdi_tables;
/
drop procedure drop_all_cdi_tables;
/
不幸的是,下降的過程會導致一個問題。似乎會導致競爭條件,並且在執行之前該過程被丟棄。
例如: -
SQL*Plus: Release 11.1.0.7.0 - Production on Tue Mar 30 18:45:42 2010 Copyright (c) 1982, 2008, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64bit Production With the Partitioning, OLAP, Data Mining and Real Application Testing options Procedure created. PL/SQL procedure successfully completed. Procedure created. Procedure dropped. drop procedure drop_all_user_tables * ERROR at line 1: ORA-04043: object DROP_ALL_USER_TABLES does not exist SQL> Disconnected from Oracle Database 11g Enterprise Edition Release 11.1.0.7.0 - 64 With the Partitioning, OLAP, Data Mining and Real Application Testing options
如何得到這個工作任何想法?
+1。不需要創建程序 – 2010-03-31 01:59:15
這是訣竅。奇怪的是,我不得不在腳本末尾添加尾部/以實際執行匿名PLSQL塊。如果我們稍後創建一個自定義的MSBUILD任務來執行腳本中的語句 - 會導致/導致問題? – Ambience 2010-03-31 15:10:32
/告訴sqlplus您的PLSQL塊已完成,並將其提交給數據庫進行處理。所以如果你的MSBUILD使用sqlplus,它將需要/。 – 2010-03-31 15:55:28