A user who has the INSERT privilege for a table can insert rows into that table.
However, if a query is specified in the INSERT statement, the user needs the SELECT privilege for the table for which the query is specified.
INSERT INTO [[RD-node-name.]authorization-identifier.]
table-identifier
{[(column-name [, column-name]...)]
{VALUES (insertion-value [, insertion-value]...)
|query-expression-body}
|DEFAULT VALUES}
[WITH ROLLBACK]
query-expression-body:: = {query-specification
|(query-expression-body)
|query-expression-body {UNION|EXCEPT}[ALL]
query-specification|(query-expression-body)}}
query-specification :: = SELECT[{ALL|DISTINCT}]{selection-expression[, selection-expression]...|*} table-expression
table-expression :: = FROM table-reference[, table-reference]...
[WHERE search-condition]
[GROUP BY value-expression[, value-expression]...]
[HAVING search-condition]
- [[RD-node-name.]authorization-identifier.]table-identifier
- RD-node-name
- Specify the RD node name of the RD node to be accessed.
- authorization-identifier
- Specifies the authorization identifier of the owner of the table.
- MASTER cannot be specified as an authorization identifier.
- table-identifier
- Specifies the name of the table into which rows are to be inserted.
- [(column-name [, column-name])]
Specifies the names of the columns into which data is to be inserted.
The following rules apply to column names:
- Rows cannot be inserted, updated, or deleted from a read-only view table (for details about read-only view tables, see Common Rules in CREATE VIEW (Define view) in 3).
- When row insertion into a view table is specified, the system inserts the rows into the base table of the view table. Any columns in the view table's base table that are not associated with a column in the view table receive the null value. Therefore, in the case of a view table defined from a base table with the FIX attribute, rows are not inserted if there are columns of the view table's base table that are not associated with columns in the view table.
- Any column that is not specified receives the null value.
- The number of elements in unspecified repetition columns will be 0.
- Not specifying any column names is equivalent to specifying all columns in the specification order of the columns when the columns were defined in the table definition.
- A subscript cannot be specified as part of a column name.
- VALUES (insertion-value [, insertion-value])
- insertion-value
- Specifies an insertion value for a specified column. The following items can be specified:
- Value expressions
- NULL (represents the null value)
- DEFAULT
- ARRAY [element-value[, element-value]...]*
- * The following can be specified in element-value:
- Value expression
- NULL (represents the null value)
- DEFAULT
- The following rules apply to insertion values:
- Insertion values must be specified in the order in which the column names are specified.
- To assign the null value as an insertion value, NULL must be specified.
- If DEFAULT is specified in insertion-value or as a value of an element in insertion-value, the predefined value of the column that is the target of insertion is inserted. If the DEFAULT clause is present, the insertion value is the specified predefined value. If the DEFAULT clause is not present but WITH DEFAULT is specified, the insertion value is the predefined value for WITH DEFAULT. If neither the DEFAULT clause nor WITH DEFAULT is present, NULL is the predefined value.
- If SYSTEM GENERATED is specified for the column associated with insertion-value, the specified insertion value is ignored; instead, the current date (CURRENT_DATE) is inserted for the DATE type, or the current time (CURRENT_TIME) for the TIME type.
- In the case of preprocessing using the PREPARE statement, an embedded variable or an indicator variable cannot be specified.
- Embedded variables must be of the same structures as the column structures of the associated columns.
- In the case of an embedded variable used to assign a value to a ? parameter, the same structure as the structure of the associated column must be specified.
- ARRAY [element-value [, element-value] ...] can be specified only if the corresponding column is a repetition column. The maximum number of elements that can be specified is 30,000, provided that they do not exceed the maximum number of elements allowed in the column into which they are inserted. The embedded variable (indicator variable) and the ? parameter for element values should be of a simple structure.
- A value expression containing a column name or a set function cannot be specified in an insertion value.
- Neither a WRITE specification nor a GET_JAVA_STORED_ROUTINE_SOURCE specification can be specified in an insertion value.
- query-expression-body:: = {query-specification
| (query-expression-body)
| query-expression-body {UNION | EXCEPT} [ALL]
{query-specification | (query-expression-body) } }
Specifies the query specification body that fetches the data to be inserted.
For details about query expression bodies, see 2.2 Query expressions.
- query-specification:: = SELECT [{ ALL | DISTINCT}]
{selection-expression [, selection-expression]... | *} table-expression
For details about query specifications, see 2.3 Query specification.
If the column into which the fetched data is to be inserted is a repetition column, specify an unsubscripted repetition column in the selection expression in the query specification associated with that column.
- table-expression:: = FROM table-reference [, table-reference]...
[WHERE search-condition]
[GROUP BY value-expression [, value-expression]...]
[HAVING search-condition]
For table expressions, see 2.5 Table expressions. For table referencing, see 2.6 Table reference. For search conditions, see 2.7 Search conditions.
Inserts a predefined value for all columns in the row to be inserted.
DEFAULT VALUES has the same meaning as the specification of the following format:
VALUES(DEFAULT,DEFAULT,...)
The number of DEFAULT specifications above is equal to the number of columns in the table that is subject to the insertion operation.
Specifies that if the table that is subject to the insertion operation is being used by another user, the transaction issued by that user is to be cancelled and invalidated.
When the WITH ROLLBACK option is omitted and the table subject to the insertion operation is being used by another user, the current user must wait until the transaction issued by that user is completed.
All Rights Reserved. Copyright (C) 2007, Hitachi, Ltd.