create table same_tbl_rownum(id varchar2(10),dt date, smv varchar2(10), sl number(10));
insert into same_tbl_rownum values('10','10-mar-18','bangla1','');
insert into same_tbl_rownum values('12','11-mar-18','bangla2','');
insert into same_tbl_rownum values('15','12-mar-18','bangla3','');
insert into same_tbl_rownum values('16','16-mar-18','bangla4','');
insert into same_tbl_rownum values('17','11-mar-19','bangla5','');
insert into same_tbl_rownum values('01','20-mar-20','bangla5','');
commit;
select * from same_tbl_rownum;
ID DT SMV SL
---------- --------- ---------- ----------
10 10-MAR-18 bangla1
12 11-MAR-18 bangla2
15 12-MAR-18 bangla3
16 16-MAR-18 bangla4
17 11-MAR-19 bangla5
01 20-MAR-20 bangla5
6 rows selected.
UPDATE same_tbl_rownum
SET sl= (select rn
from (
select rowid,
row_number() over (order by dt) AS RN
from same_tbl_rownum
) x
where x.rowid = same_tbl_rownum.rowid)
/
select * from same_tbl_rownum ;
ID DT SMV SL
---------- --------- ---------- ----------
10 10-MAR-18 bangla1 1
12 11-MAR-18 bangla2 2
15 12-MAR-18 bangla3 3
16 16-MAR-18 bangla4 4
17 11-MAR-19 bangla5 5
01 20-MAR-20 bangla5 6
6 rows selected.
No comments:
Post a Comment