INSERT...SELECT
The INSERT...SELECT
statement inserts the results of a query into a table.
Required privilege
No privilege is required for the object owner.
INSERT
and SELECT
for another user's object.
Usage with TimesTen Scaleout
This statement is supported with TimesTen Scaleout.
SQL syntax
INSERT INTO [Owner.]TableName [(ColumnName [,...])] InsertQuery
Parameters
Parameter | Description |
---|---|
|
Table to which data is to be added. |
|
Column for which values are supplied. If you omit any of the table's columns from the column name list, the |
|
Any supported |
Description
-
The column types of the result set must be compatible with the column types of the target table.
-
You can specify a sequence
CURRVAL
orNEXTVAL
when inserting values. See "Using CURRVAL and NEXTVAL in TimesTen Classic" for more details. -
In the
InsertQuery
, theORDER BY
clause is allowed. The sort order may be modified using theORDER BY
clause when the result set is inserted into the target table, but the order is not guaranteed. -
The
INSERT
operation fails if there is an error in theInsertQuery
. -
A
RETURNING
clause cannot be used in anINSERT...SELECT
statement. -
The
SELECT
subquery in aUNION
,UNION
ALL
,MINUS
, orINTERSECT
must have the same number of projected expressions.
Examples
New rows are added to the purchasing.parts
table that describe which parts are delivered in 20 days or less.
INSERT INTO purchasing.parts SELECT partnumber, deliverydays FROM purchasing.supplyprice WHERE deliverydays < 20;