是这样的 select t.table_name from user_tab_comments t where 1=1 这条语句能查询出当前用户下所有的表的表名。
我现在需要一个存储过成。。
就是循环 执行truncate table "+tableName+"  这个tableName 就是以上语句查询出来的一个列表我的一个想法(不知道是否争取)。。其需求反正就是清空当前数据库中所有表的数据。高手还有其他办法么?

解决方案 »

  1.   


    create or replace procedure truncate_table
    as
      cursor c_v is
      select table_name
      from user_tab_comments;
    begin
         for c in c_v loop
             execute immediate 'truncate table '||c.table_name;
             commit;
         end loop;
         exception
           when others then
             rollback;
    end truncate_table;
      

  2.   

    还是要慎重的考虑,因为select t.table_name from user_tab_comments t where 1=1 
    将会查询出很多表,或者其中包含的非常重要的表,但是你却将其数据删除了。
    个人觉得还是使用truncate table table_name来指定清除数据的表,一个一个的来
      

  3.   

    select table_name from user_tables;
    user_tables数据字典视图里面才存着表的信息
      

  4.   


    我就是这样理解的么..
    你的意思就是这个 truncate table table_name 中 这个 table_name 传进去 要慎重。。
      

  5.   

    对,一个一个表的清除数据:
    truncate table table_name
    这样比较安全!