日期:2014-05-17  浏览次数:20700 次

求sql:如何查找以某些字符开头的用户表,并清空其中的内容
用户a有很多表,需要查找以tabdc开头的表,并清空其中的内容,求sql语句。谢谢!!!

------解决方案--------------------
select * from all_tables where owner = 'A ' and table_name like 'tabdc% '
------解决方案--------------------
查找表
select * from dba_tables where table_name like 'TABDC% ' and owner = 'A '

要自动清空应该用pl/sql。
------解决方案--------------------
循环取得相应的表名,然后
truncate table table_name,可以写个过程。注意truncate的使用,效率高但数据不能回滚。
如:
create or replace procedure clear_table_p()
as
v_sql varchar2(100);
begin
for cur in select table_name from all_tables where table_name like 'TABDC% ' and owner = 'A ' loop
v_sql := truncate table cur.table_name;
execute immediate v_sql;
end loop;
end;
/