I have difficulty with some task which need loop. As Im pl/sql newbie I don;t know exactly how to aproach that issue, Could anyone take a look?
Maybe the easiest way is to present than describe what I want to do:
Select id from table1 t1 join table2 t2 on t1.column=t2.column2
insert into table2 id from previous operation.
Select id from table1 t1 join table2 t2 on t1.column=ts.column2 where t1.id in (Select id from table1 t1 join table2 t2 on t1.column=t2.column2);
insert into table2 id from previous operation
And now if previous operation return some data then do:
Select id from table1 t1 join table2 t2 on t1.column=t2.column2 WHERE t1.column in (Select id from table1 t1 join table2 t2 on t1.column=ts.column2 where t1.id in (Select id from table1 t1 join table2 t2 on t1.column=t2.column2)
insert into tablr2 id from previous operation
and so on, until select will not return nothing.
Of course I realise that "select" will insert duplicate ID into table3. I know only that i have to use loop but don't know exactly which one and how. Is is possible to handle with that?
edit:
All right once again, I have 2 tables:
Table1
Column1
1
2
3
4
5
6
7
8
9
Table2
Column1 Column2 Column3
2345 1 0
5346 2 0
67542 3 23432
3452 4 324665
64356 5 34234
23432 6 0
324665 7 67867
34234 8 0
67867 9 9
Table to insert:
ID
1
2
3
4
And as input I got Table3 with ID which I want to INSERT into eg. Table4 (ID).
But some of that ID probably can have some parent/child ID. And that's the main difficult how to do that in the loop. Generally we can find parent/child ID by using statement:
select ID from table1 t1 join Table2 t2 on t1.id=t2.Column2 join Table2 t2 on t2.Column3=t2.Column1
And Now base on "Table to insert" insert statement (into Table4) should insert values: 1,2,3,4 + 6 and 7 (as we can see 6 and 7 has parent id (Column0 ! = 0).
And now we want to check if any of account 6,7 has parent/child ID same as before. So insert into Table4 should insert values: 9 End.
Of course that's only situation describe 2-3 iteration, what If there will be more parent/child ID?
I thought to use some table type, and somehow after every loop put ID to check into table variable and use it to other iteration...
insert into table2 select ...
statement - no need for row-by-row aka slow-by-slow processing! – BoneistCONNECT BY
- is that what you're looking for? – Jon Heller