Skip to content
Advertisement

insert into two different tables from two different tables

When i try this, i got error

“ORA-06550: line 2, column 48: PL/SQL: ORA-00926: missing VALUES keyword ORA-06550: line 2, column 1: PL/SQL: SQL Statement ignored”.

I need to insert some values from different tables to two different tables.

assume table 1 and table 2 are like ,

table 1
x|y   ---> column names
a b   ---> values

table 2
z|k   --->c.n
c d   --->val.

As you see i need to copy some rows with little changes to its own table.But i have two different tables and I should do that at the same time.

INSERT INTO table1.a,table1.b,table2.c,table2.d
SELECT x,y,z,k
FROM table1
FULL JOIN table2_ALT ON table1.x=table2.z
WHERE ....

or

INSERT INTO table1.a,table1.b,table2.c,table2.d
SELECT table1.x,table1.y,table2.z,table2.k
FROM table1
FULL JOIN table2_ALT ON table1.x=table2.z
WHERE ....

Advertisement

Answer

You can try something similar like given below: Read more about INSERT ALL for inserting into multiple tables.

INSERT ALL 
INTO 
table1(a,b) values(a, b)
INTO table2(c,d) values(c, d) 
SELECT table1.x as a,table1.y as b,table2.z as c,table2.k as d
FROM table1
FULL JOIN table2_ALT ON table1.x=table2.z
WHERE ....
User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement