'Insert a number sequence into 3 different tables using 1 oracle table column
I have a table T1 contains column C1 which has values (1,2,3,4....3000). I need to populate these records into 3 Tables T2,T3,T4 in the following form: Values T2:1,4,7,10.... T3:2,5,8,11.... T4:3,6,9,12....
How can I write SQL to do this.
Solution 1:[1]
You may use multitable insert for this:
insert all when grp = 0 then into t1(id) values(rn) when grp = 1 then into t2(id) values(rn) when grp = 2 then into t3(id) values(rn) select t.*, mod(rn-1, 3) as grp from t9 rows affected
select 'T1' as src, id from t1 union all select 'T2', id from t2 union all select 'T3', id from t3SRC | ID :-- | -: T1 | 1 T1 | 4 T1 | 7 T2 | 2 T2 | 5 T2 | 8 T3 | 3 T3 | 6 T3 | 9
db<>fiddle here
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | astentx |
