SQL> **select 'drop table '||table_name||';' from cat where table_type='TABLE';**
'DROPTABLE'||TABLE_NAME||';'
drop table TT_TEST_USER;
drop table TRACE_USER;
drop table TO_SJYZX_DATE;
drop table TMP_LUZP$LOCK;
drop table TJ_ZQLAN_ACTIVE_201602;
drop table TJ_ZQLAN_ACTIVE_201601;
drop table TJ_ZQLAN_ACTIVE_201512;
drop table TJ_ZQLAN_ACTIVE_201511;
drop table TJ_ZQLAN_ACTIVE_201510;
drop table TJ_ZQLAN_ACTIVE_201509;
drop table TJ_ZQLAN_ACTIVE_201507;
drop table TJ_ZQLAN_ACTIVE_201506;
drop table TJ_ZQLAN_ACTIVE_201505;
drop table TJ_ZQLAN_ACTIVE_201504;
drop table TJ_ZQLAN_ACTIVE_201503;
drop table TJ_ZQLAN_ACTIVE_201502;
drop table TJ_ZQLAN_ACTIVE_201501;
drop table TJ_ZQLAN_ACTIVE_201412;
drop table TJ_ZQLAN_ACTIVE_201411;
drop table TJ_ZQLAN_ACTIVE_201410;
'DROPTABLE'||TABLE_NAME||';'
有没有办法可以直接生产一个脚本或者自动加载到一个文本文件,直接执行一条语句全删。
而不是需要将所有drop table xyz复制进文本文件再@D:+路径删除
你可以把所有的表名存在一个文件里,然后用批处理读取出来,拼接一下,自动产生一个新文件,然后执行
或者用高级语言/vbs/shell等各种你会的语言编程来解决
但是表名是必须的,没人知道你到底要删什么表,总不能数据库里所有表都删吧,真删了你数据库就废了。
可以在存储过程里执行动态sql,以oracle数据库为例
begin
for rec in (select 'drop table '||table_name||';' str from cat where table_type='TABLE') loop
execute immediate rec.str;
end loop;
end;
/
其他数据库也有类似的动态sql执行方式