日期:2014-05-16  浏览次数:21036 次

Oracle update1条记录
从java程序中,循环生成了196个编码,需要分别更新到数据库中的196条记录中
每循环一次,需要执行一个update语句,将1个编码更新到数据库196条记录中任何一条
再次循环,再次更新
我的sql语句是这样写的:
create or replace procedure pro_ghxCode(p_ghxCode in varchar2)
is
begin
   
  update card_zonghe a set a.emscode = p_ghxCode
  where a.cardno in (select cardno from card_in_out_store 
  where riqi = to_char(sysdate,'yyyymmdd')) 
  and is_mailing = 'Y' 
  and yjflag = '1' 
  and store_state = 'ZKZX' 
  and card_state = 'PRE_STORE_OUT'
  and rownum = '1';

  
  commit;
end pro_ghxCode;
用rownum = '1'第一次可以保证1个编码更新到一条记录中
第二次就不可以了,总之rownum 是不可取的
各位高手,有没有好的解决办法啊?

------解决方案--------------------
更新前emscode字段有值吗,如果没有的话可以用这个字段判断.
SQL code
update card_zonghe a set a.emscode = p_ghxCode,a.标识字段名='Y'
  where a.cardno in (select cardno from card_in_out_store  
  where riqi = to_char(sysdate,'yyyymmdd'))  
  and is_mailing = 'Y'  
  and yjflag = '1'  
  and store_state = 'ZKZX'  
  and card_state = 'PRE_STORE_OUT'
  and emscode is null--这里改成 and 标识字段名='N'
  and rownum = 1;