如何在PROCEDURES中寫一個UPDATEUPDATE必須要給WHERE條件告訴他要修改哪些資料
如果說我今天只有要修改最靠近今天日期的5筆資料
請問我該如何撰寫這個UPDATE
UPDATE A,B
SET A.A1=B.B1
WHERE (這裡開如何撰寫最靠近今天日期的前五筆資料??)

解决方案 »

  1.   

    --你表里应该有个时间的字段吧例如col
    UPDATE A,B
    SET A.A1=B.B1
    WHERE col-sysdate<=5--如果是varchar2
    --(to_date(col,'yyyymmdd')-sysdate)<=5
      

  2.   

    看错了 以为是最近5天的
    merge into a
    using(select a.*,row_number() over(order by col) rn 
          from tablename where rn<=5) b
    on a.主键=b.主键
    when matched then
    update
    a.a1=
      

  3.   

    Dear  zhuomingwang:
    請問 
    update
    a.a1=的語法是????跟我上面所寫的一樣嗎??
      

  4.   


    --查询出最靠近当前日期的5条数据
    select * from A where dtcol < to_number(to_char(sysdate,'yyyyMMdd')) and rownum <=5--加入到你的where部
    UPDATE A,B
    SET A.A1=B.B1
    WHERE dtcol in (select * from A where dtcol < to_number(to_char(sysdate,'yyyyMMdd')) and rownum <=5)
    或者你用exists方式也可
      

  5.   


    UPDATE A SET A1=(select B1 from B where 关联字段)
    WHERE  a1 in(select a1
    from (select a1,
    row_number() over(partition by a1 order by dt) rn 
    from A where to_char(a.dt,'yyyy-mm-dd')='2010-11-08') where rn<=5)
      

  6.   

    update table a
       set a.col = num_you_want
     where a.rowid in (select rowid
                         from (select b.col
                                 from table b
                                where b.col < sysdate
                                order by b.col)
                        where rownum <= 5)
      

  7.   

    Dear lxyzxq2008
    謝謝您的幫忙
    我的oracle好像沒有這麼新餒@@我的是比8i舊的
    請問有沒有比較舊的寫法壓
    ??