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
CURRVALorNEXTVALwhen inserting values. See "Using CURRVAL and NEXTVAL in TimesTen Classic" for more details. -
In the
InsertQuery, theORDER BYclause is allowed. The sort order may be modified using theORDER BYclause when the result set is inserted into the target table, but the order is not guaranteed. -
The
INSERToperation fails if there is an error in theInsertQuery. -
A
RETURNINGclause cannot be used in anINSERT...SELECTstatement. -
The
SELECTsubquery in aUNION,UNIONALL,MINUS, orINTERSECTmust 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;