updatesql="update DocClauses set CLAUSEORDER=CLAUSEORDER-1 where (CLAUSEID=?) or (ITEMID=? and CLAUSEORDER=?) ";

解决方案 »

  1.   

    "
    update DocClauses set CLAUSEORDER=CLAUSEORDER-1 where CLAUSEID=?;
    update DocClauses set CLAUSEORDER=CLAUSEORDER+1 where ITEMID=? and CLAUSEORDER=?;
    "
    语句后加上分号
      

  2.   

    对同一张表的两个记录(a,b)进行操作,表里有个字段是记录顺序的,我有两个记录,a的顺序字段值是7,b的顺序字段值是8,我要把两个顺序换换,把a的顺序字段值变成8,b的顺序字段值变成7,不知道怎么写,可以用一句SQL语句写出来????
      

  3.   

    updatesql="update DocClauses set CLAUSEORDER=DECODE('A','A',CLAUSEORDER-1,'B', CLAUSEORDER+1) where DECODE('A','A',(CLAUSEID=?),'B',(ITEMID=? and CLAUSEORDER=?) )";
      

  4.   

    updatesql="update DocClauses set CLAUSEORDER=DECODE('A','A',CLAUSEORDER-1, CLAUSEORDER+1) where DECODE('A','A',(CLAUSEID=?),(ITEMID=? and CLAUSEORDER=?) )";
      

  5.   

    CREATE or replace package pktest is
         procedure proc_test(iCLAUSEID number, iITEMID number, iCLAUSEORDER number);
    end cw;
    /CREATE or Replace package body pktest is
    procedure  proc_test((iCLAUSEID number, iITEMID number, iCLAUSEORDER number) 
    as
    begin
    update DocClauses set CLAUSEORDER=CLAUSEORDER-1 where CLAUSEID=iCLAUSEID;
    update DocClauses set CLAUSEORDER=CLAUSEORDER+1 where ITEMID=iITEMID 
     and CLAUSEORDER = iCLAUSEORDER ;
    end proc_test;
      

  6.   

    "两句SQL语句合在一起?"
    是為什麼呢?两句SQL语句分開執行或合在一起執行在同一個事務下是完全沒有區別的!update table b
    set    b.id=
          ( 
           select a.id 
           from  (
                  select id,id-1 id_x from table
                  where  id = 8
                  union 
                  select id,id+1 id_x from table
                  where  id = 7 
                 ) a
           where b.id=a.id_x
          )
    where b.id in (7,8);
      

  7.   

    我在写JAVA程序的时候,必须合在一起写,没办法,qiaozhiwei(乔)兄,刚才好象不行哦
      

  8.   

    SQL> update DocClauses set CLAUSEORDER=DECODE('A','A',CLAUSEORDER-1,'B', CLAUSEORDER+1) where DECODE
    ('A','A',
      2  (CLAUSEID='487'),'B',(ITEMID='484' and CLAUSEORDER='3'));
    (CLAUSEID='487'),'B',(ITEMID='484' and CLAUSEORDER='3'))
             *
    ERROR 位于第 2 行:
    ORA-00907: 缺少右括号
      

  9.   

    如果都要执行.是否可以考虑在两条之间加commit?!
      

  10.   

    楼主,先问一个简单的问题,如果
    CLAUSEID=? 和 ITEMID=? and CLAUSEORDER=? 都满足,执行什么?
      

  11.   

    如果没有这种情况则可以这样写:
    update DocClauses set CLAUSEORDER = (
    select CLAUSEORDER-1 where CLAUSEID=?
    );
    update DocClauses set CLAUSEORDER=CLAUSEORDER-1 where CLAUSEID=?";
    tempsql="update DocClauses set CLAUSEORDER=CLAUSEORDER+1 where ITEMID=? and CLAUSEORDER=?";
      

  12.   

    不好意思,一下子,不弄好搞错!
    如果没有同时满足CLAUSEID=? 和 ITEMID=? and CLAUSEORDER=? 这种情况则可以这样写:
    update DocClauses a
                  set CLAUSEORDER = (
                                     select CLAUSEORDER-1 from DocClauses b 
                                          where a.识别码= b.识别码 and CLAUSEID=?
                                     union 
                                     select CLAUSEORDER-1 from DocClauses b 
                                          where a.识别码= b.识别码 and ITEMID=? 
                                          and  CLAUSEORDER=?
                                     )
                 where CLAUSEID=? or (ITEMID=? and CLAUSEORDER=?);
    如果有那种情况则要再加个查询:
    update DocClauses a
                  set CLAUSEORDER = (
                                      select max(c.aa) --你要的函数 
                                      from
                                      (select CLAUSEORDER-1 aa from DocClauses b 
                                          where a.识别码= b.识别码 and CLAUSEID=?
                                        union 
                                        select CLAUSEORDER+1 aa from DocClauses b 
                                          where a.识别码= b.识别码 and ITEMID=? 
                                          and  CLAUSEORDER=?
                                       )c
                                     )
                 where CLAUSEID=? or (ITEMID=? and CLAUSEORDER=?);