oracle 删除所有表 sql developer
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/18030140/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Drop all tables sql developer
提问by Emad Aghayi
I have tables that names start with "TBL_*", but I can not dropall of them by single command.
我有名称以“TBL_*”开头的表,但我无法通过单个命令删除所有表。
how can I drop this tables?
我怎样才能放下这张桌子?
回答by T.S.
You can write a script, specifically, loop, in which you select Table_name from user_tables and iterate this loop , and use "execute immediate" command to drop them.
您可以编写一个脚本,特别是循环,在其中您从 user_tables 中选择 Table_name 并迭代此循环,然后使用“立即执行”命令删除它们。
But I would suggest this - in sql tool do
但我建议这样做 - 在 sql 工具中做
select 'drop table ' || table_name || ';' from user_tables where table_name like 'TBL_%'
Then you copy output of this query and paste into your sql editor, and execute. Remember, if sql+ is your editor, if you paste them all, they will start execute. May be you want to use notepad to review and edit it first.
然后你复制这个查询的输出并粘贴到你的 sql 编辑器中,然后执行。请记住,如果 sql+ 是您的编辑器,如果您将它们全部粘贴,它们将开始执行。可能您想先使用记事本进行查看和编辑。
But you can't just drop more than one table in one single command. Check this link for other options associated with drop table http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9003.htm
但是您不能只在一个命令中删除多个表。检查此链接以获取与删除表相关的其他选项http://docs.oracle.com/cd/B19306_01/server.102/b14200/statements_9003.htm
回答by Frank
BEGIN
--Bye Tables!
FOR i IN (SELECT ut.table_name
FROM USER_TABLES ut) LOOP
EXECUTE IMMEDIATE 'drop table '|| i.table_name ||' CASCADE CONSTRAINTS ';
END LOOP;
END;