Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Insert Multiple rows using results from another query...

leonhardtkJul 12 2013 — edited Jul 16 2013

I need to take values from the column of one table that meets certain critera, and create inserts into another table that includes this data.

For example...

{code}

select emp_last_name from emp where emp_first_name like 'B%';

Duncan

Fitzgerald

Johnson

Smith

{code}

I then want to insert these values into another table:

{code}

insert into My_table values (

sequence.nextval,99,99,[last_name]);

{code}

In the example above, I need it to insert a new row into My_table for where the "last_name" is each of the names from the select statement above (Duncan, Fitzgerald,Johnson,Smith).

Based on other similar forum questions it looks like I should be doing something like:

{code}

INSERT INTO MY_TABLE

(SELECT sequence.nextval,

                99,

                99,

               (select EMP_LAST_NAME

                FROM EMP

                WHERE EMP_FIRST_NAME LIKE 'B%')

);

{code}

But this (obviously) doesn't work!

Appreciate any assistance on this!

KSL.

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 13 2013
Added on Jul 12 2013
13 comments
3,201 views