Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do we have to make a SELECT after an 'INSERT ALL'?

Tags:

sql

oracle

As I seen on many sites, if I want to make an INSERT ALL, I have to finish it with a SELECT (Like SELECT * FROM dual;)

Why?

like image 664
Acibi Avatar asked Jul 01 '10 09:07

Acibi


1 Answers

A subquery is mandatory per the syntax of INSERT ALL (see http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/statements_9014.htm#i2111652)

the insert clause is executed for each row returned by the subquery (i.e. the SELECT statement). SELECT * FROM dual returns a single row, so the insert_clause(s) is executed once (which is useful when you want to insert a hardcoded set of values)

like image 76
potatopeelings Avatar answered Oct 01 '22 15:10

potatopeelings