在 oracle10g 中 如何删除一个用户下面的所有表的数据 但是表的结构还在
请高手指点

解决方案 »

  1.   

    用个循环
    从user_table中得到表名...再一个个truncate...
    想一起删恐怕做不到.
      

  2.   

    select 'truncate table '||table_name||';' from user_tables;
    先取得删除数据语句然后执行就行了
      

  3.   

    -- 以将要删除用户登录
    SQL> SPOOL D:\TRUN.SQLSQL> SELECT 'TRUNCATE TABLE '||TABLE_NAME FROM USER_TABLES;SQL> @D:\TRUN.SQL
      

  4.   


    SQL> SPOOL clear.SQLSQL>select 'alter table ' || t.table_name || ' disable constraint ' ||t.constraint_name||';' 
    from user_constraints t  
    where t.constraint_type = 'R';SQL> SELECT 'TRUNCATE TABLE  '||TABLE_NAME||';' FROM USER_TABLES;SQL>select 'alter table ' || t.table_name || ' enable constraint ' ||t.constraint_name||';' 
    from user_constraints t  
    where t.constraint_type = 'R';SQL> clear.SQL有外键不能truncate
      

  5.   

    create or replace procedure truncatetables is
      l_row user_all_tables%rowtype;
      sqlstr varchar2(1000);
      cursor tablesa is select * from user_all_tables;
      cc number;
    begin
      open tablesa;
      loop
         fetch tablesa into l_row;
         sqlstr := 'truncate table '||l_row.table_name;
    --     dbms_output.put_line(sqlstr);
         begin
         execute immediate sqlstr;
         exception
         when others then
             dbms_output.put_line(sqlstr||'执行错误');
         end;
         dbms_output.put_line(l_row.table_name||'记录条数:'||cc);
         select 0 into cc from dual;
         exit when tablesa%notfound;
      end loop;
      close tablesa;
    end;先建立这个存储过程 然后运行
    begin
      truncatetables;
    end;
    就可以清空表内数据了