create table T1 (ID_NUM int, PARENT_ID_NUM int, SIBLING_ORDER int)
Table created.
insert into T1
(ID_NUM, PARENT_ID_NUM, SIBLING_ORDER)
select 1, null, null from dual union
select 4, 1, 5498 from dual union
select 3, 1, 73 from dual union
select 2, 1, -6 from dual
4 row(s) inserted.
commit
Statement processed.
select * from T1
ID_NUM | PARENT_ID_NUM | SIBLING_ORDER | 1 | - | - | 2 | 1 | -6 | 3 | 1 | 73 | 4 | 1 | 5498 |
---|
update T1
set SIBLING_ORDER = rownum
where PARENT_ID_NUM = 1
3 row(s) updated.
select * from T1
ID_NUM | PARENT_ID_NUM | SIBLING_ORDER | 1 | - | - | 2 | 1 | 1 | 3 | 1 | 2 | 4 | 1 | 3 |
---|
update T1
set SIBLING_ORDER = 3 - SIBLING_ORDER
where PARENT_ID_NUM = 1
3 row(s) updated.
select * from T1
ID_NUM | PARENT_ID_NUM | SIBLING_ORDER | 1 | - | - | 2 | 1 | 2 | 3 | 1 | 1 | 4 | 1 | 0 |
---|
update T1
set SIBLING_ORDER = rownum
where PARENT_ID_NUM = 1
3 row(s) updated.
select * from T1
ID_NUM | PARENT_ID_NUM | SIBLING_ORDER | 1 | - | - | 2 | 1 | 1 | 3 | 1 | 2 | 4 | 1 | 3 |
---|
commit
Statement processed.
Possible solution
update T1
set SIBLING_ORDER = 3 - SIBLING_ORDER
where PARENT_ID_NUM = 1
3 row(s) updated.
Possible solution
merge into T1 f
using (
with x (ID_NUM, SIBLING_ORDER) as (
select ID_NUM,
row_number() over (partition by PARENT_ID_NUM order by SIBLING_ORDER, ID_NUM)
from T1
where PARENT_ID_NUM = 1
)
select ID_NUM, SIBLING_ORDER from x
) sib
on (
f.ID_NUM = sib.ID_NUM
)
when matched then
update
set f.SIBLING_ORDER = sib.SIBLING_ORDER
where f.ID_NUM = sib.ID_NUM
Statement processed.
Possible solution
commit
Statement processed.
Possible solution
select * from T1
ID_NUM | PARENT_ID_NUM | SIBLING_ORDER | 1 | - | - | 2 | 1 | 3 | 3 | 1 | 2 | 4 | 1 | 1 |
---|