删除所有外键,删除所有表

create or replace procedure pro_droptable is
cursor cur is select table_name from user_tables;
drop_sql varchar2(1000);
begin
/**删除所有的外键**/
for c in (select 'ALTER TABLE '||TABLE_NAME||' DROP  CONSTRAINT '||constraint_name||' ' as v_sql from user_constraints where CONSTRAINT_TYPE='R') loop
DBMS_OUTPUT.PUT_LINE(C.V_SQL);
begin
EXECUTE IMMEDIATE c.v_sql;
exception when others then
dbms_output.put_line(sqlerrm);
end;
end loop;
/** 删除表**/
  for tbname in cur loop
    begin
      drop_sql:='drop table '||tbname.table_name;
      execute immediate drop_sql;
    end;
  end loop;
end pro_droptable;

猜你喜欢

转载自wujt.iteye.com/blog/1313535