2

I have a procedure that is receiving some values from our application, I need to insert these static values and the results of a subquery to one of our tables. Is this possible with one insert statement? So it would look like this

Insert into table
values 
(value1, value2, value3, (select testdata from dual));

The resulting table would look like:
value1 | value2 | value 3 | ROW 1 FROM SUBQUERY
value1 | value2 | value 3 | ROW 2 FROM SUBQUERY

I know that if I was only using a subquery I would omit the values command and vice versa with actual values. Does anyone have experience with this one?

Quartzee
  • 25
  • 2

2 Answers2

4

Yes, but you do it only with a select:

Insert into table
    select value1, value2, value3, testdata
    from dual;

That is, you add the values as constants on the select line.

Gordon Linoff
  • 1,242,037
  • 58
  • 646
  • 786
0

Use INSERT INTO tablename SELECT xxx FROM command.

INSERT INTO tablename ( col1, col2, ... colN)
-- select rows from first subquery
SELECT x1, x2, ... xN FROM ......
UNION ALL
-- select rows from second subquery
SELECT y1, y2, ... yN FROM ......
krokodilko
  • 35,300
  • 7
  • 55
  • 79