oracle9i 有一张表TN(id,name,age,time),我想删除这张表里time小于20081010的记录,该怎么写存储过程?
说明:我是初学者,对存储过程没概念,所以请大家指教时写上注释,最好写详细点。

解决方案 »

  1.   

    delete from tn where time<to_date('20081010','yyyymmdd');
    非要写存储过程
    create or replace pro_delete
    as 
    begin
    delete from tn where time<to_date('20081010','yyyymmdd');---删除语句
    commit;--提交
    end;
      

  2.   

    补充:
    还有两张表TNa(id,nid,...)、TNb(id,nid...)与TN关联。TNa.nid、TNb.nid都与TN.id是对应的。
      

  3.   

    为什么要写存储过程?
    直接用SQL就好了嘛
    delete from tn where time<to_date('20081010','yyyymmdd');
      

  4.   

    delete from tn where time<to_date('20081010','yyyymmdd') and exists select(1 from tn,TNa,TNb whre
    TNa.nid=tn.id and tn.id=tnb.id)
      

  5.   

    delete from tna where nid=' ';
    delete from tnb where nid=' ';
    commit;或是写个触发器删除TNA的时候同时删除TnbCreate or repalce trigger tri_tna
          after delete 
          on tna
          for each row
    begin
         if deleting then
             delete from tnb where nid=:old.nid;
         end if;
         EXCEPTION
           WHEN others THEN
            null;
    end;
         
      

  6.   

    delete
      from tn
     where exists
      (
      select 1
        from tna, tnb
       where tna.nid = tn.id
         and tnb.nid = tn.id
      )
      

  7.   

    慎用!conn 用户名/密码@连接串;
    set heading off
    set feedback off
    select 'drop trigger '||' '||object_name||' ;' from user_objects ;
    set heading on
    set feedback on
    commit;
      

  8.   

    谢谢大家。其实一般的SQL我会写几句,比如删除什么的。我现在遇到的问题是删TN时很慢很慢,删一条要好几秒!看网上有类似的问题,大家给的建议是用存储过程,说是能快些,所以现在就跑来求助存储过程了。