database - updating on the basis of row num -
hi want chunk data on basis of row num im failing when im trying update
declare temp varchar2(50); low varchar2(50); upp varchar2(50); begin low :=0; in ( select to_char(floor(rownum/10) * 10) low, to_char(floor(rownum/10) * 10 + 10 -1 ) upp emp group floor(rownum/10) order floor(rownum/10)) loop update emp set thd=2 rownum>i.low , rownum<i.upp; commit; low:=low+1; dbms_output.put_line(i.low|| i.upp); end loop; end;
the code updating first 10 rec correctly not updating next cycles 20-30 30-40
any guess why
in oracle pseudocolumn rownum
returns number indicating order in oracle selects row table. can use rownum < n
. rownum > n
return empty result set. because first returned row rownum = 1
, expect > n
. that's why no rows update. documentation
if have id in table can that:
merge emp e using (select * (select e2.*, row_number() on (order id) r emp e2) r > 10 , r < 21) d on (e.id = d.id) when matched update set thd = 2;
if don't have id can use cursor update
.
Comments
Post a Comment