I have these tables:
A {
id,
name
}
B {
id,
name,
aId
}
aId
is a foreign key to table A
So I have a list of strings that need to be inserted into table B.
List: names['name1', 'name2']
Also I have a select statement that fetches me a list of A.id's.
List: id's[1, 2]
The problem is that Table B needs to have rows inserted to it for every A.id that was queried and at the same time the string list should be taken into consideration.
End result would be that I get id's (1, 2) for instance, so 4 rows are created (2 for each id because every id needs to insert all the string in the list):
insert into b (id, name, aId) values (b_id_seq.nextval, name1, 1)
insert into b (id, name, aId) values (b_id_seq.nextval, name2, 1)
insert into b (id, name, aId) values (b_id_seq.nextval, name1, 2)
insert into b (id, name, aId) values (b_id_seq.nextval, name2, 2)
What I have gotten to work is write the select statement which returns an array of id's. I also tried to implement a select with these 2 lists but without luck.
First attempt was to use IN
clause inside of specific column value part and second attempt was to use INSERT ALL. Could not figure out how to generate the insert statements dynamically in the last case tough.
How would one solve this kind of INSERT statement?