Oracle 中如何刪除乙個使用者擁有的所有物件

2021-05-01 06:36:44 字數 2350 閱讀 9167

下面的指令碼在oracle中如何將乙個使用者所擁有的所有物件,表,sequence,procedure。。。全部刪掉。

1,drop 物件的方式,注意要先將所有的外來鍵約束刪掉。

declare

type cst_table_list is table of varchar2(40);

type cst_list is table of varchar2(40);

type name_list is table of varchar2(40);

type type_list is table of varchar2(20);

cst_tab_name cst_table_list:=cst_table_list();

cst_name cst_list:=cst_list();

tab_name name_list:=name_list();

tab_type type_list:=type_list();

sql_str varchar2(500);

v_err_code number;

v_err_msg varchar2(200);

begin

-- drop all reference constraints begin

sql_str := 'select table_name,constraint_name from user_constraints where constraint_type=''r''';

execute immediate sql_str bulk collect into cst_tab_name,cst_name;

for i in cst_tab_name.first.. cst_tab_name.last loop

begin

sql_str := 'alter table ' || cst_tab_name(i) || ' drop constraint ' || cst_name(i);

execute immediate sql_str;

dbms_output.put_line(sql_str);

exception

when others then

v_err_code := sqlcode;

v_err_msg := substr(sqlerrm, 1, 200);

dbms_output.put_line ('error code: '||v_err_code);

dbms_output.put_line ('error message: '||v_err_msg);

end;

end loop;

-- drop all reference constraints end

-- drop all tables, sequences...  begin

sql_str := 'select uo.object_name,uo.object_type

from user_objects uo

where uo.object_type not in(''index'',''lob'')

order by uo.object_type desc';

execute immediate sql_str bulk collect into tab_name,tab_type;

for i in tab_name.first.. tab_name.last loop

begin

sql_str := 'drop ' || tab_type(i) || ' ' || tab_name(i);

execute immediate sql_str;

dbms_output.put_line(sql_str);

exception

when others then

v_err_code := sqlcode;

v_err_msg := substr(sqlerrm, 1, 200);

dbms_output.put_line ('error code: '||v_err_code);

dbms_output.put_line ('error message: '||v_err_msg);

end;

end loop;

-- drop all tables, sequences...  end

end;

2,刪除使用者的方式,但是要有drop user的許可權且user建立的時候必須劃分出其專用的tablespace 。

drop user username cascade;

drop tablespace username_tablespace including contents and datafiles;

刪除乙個Oracle使用者的物件

刪除某個使用者下的物件 set heading off set feedback off spool c dropobj.sql prompt drop tables select drop table table name chr 13 chr 10 from user tables prompt...

新建乙個使用者操作oracle

今天出現了乙個問題,linux下root使用者不能切換到oracle使用者,但是能切換到其他的使用者,症狀如下 root localhost su oracle root localhost root localhost who am i root pts 1 2010 10 08 10 53 19...

如何刪除掉乙個使用者下的所有物件

create or replace procedure drop all ascursor cur obj is select uo.object name,uo.object type from user objects uo where uo.object name not in drop al...