Swi*_*tch 3 sql database oracle plsql
我想删除一个表空间中的某些表,这些表的公共名称附加到每个表的末尾,例如:
TABLE1_NAME1_COMMON
TABLE2_NAME2_COMMON
TABLE3_NAME3_COMMON
Run Code Online (Sandbox Code Playgroud)
我听说过Oracle功能,但我对这些功能并不熟悉,所以我期待一些帮助.
谢谢.
如果你完全确定你在做什么,也就是说,如果你确定你不小心丢弃了一个你不想丢弃的桌子,你可以做一个:
set serveroutput on size 1000000
begin
for r in (
select table_name
from user_tables
where table_name like '%\_COMMON' escape '\')
loop
execute immediate 'drop table ' || r.table_name;
end loop;
exception when others then
dbms_output.put_line(sqlerrm);
end;
/
Run Code Online (Sandbox Code Playgroud)
编辑:
user_tables而不是dba_tables看起来更安全.set serveroutput on以便dbms_output.put_line打印begin .. exception .. end以便显示错误.