SQL INSERT Statement

PURPOSE:  This statement adds or inserts one or more rows of data into the specified table.  If the VALUES clause and select_str_exp are not specified, the values for the columns will come from the READY area.

Syntax

SQL INSERT /INTO/ table_name [ (column_list) ]
    {VALUES ( \\constant_expression\\ ) } [HUSH]

table_name

is the table to which data will be added.

(column_list)

a list of one or more columns for the specified table.  The columns can be in any order, but the incoming data must be in the same order.  Note that the parentheses must be entered as a part of the statement.

The column_list is only necessary when some, but not all, of the columns in the table are to receive data.  The column_list determines the order in which values are entered.  If a column_list is not specified, all of the columns in the table are assumed to be receiving data.  In this case, the order of the columns is assumed to be the same as used when the table was created.

VALUES

specifies the field or constant values for the indicated columns.

(\\constant_expression\\)

The value list must match the explicit or implicit column_list.  Note that the parentheses must be entered as a part of the statement.  Use of the Ready statement will allow values to be placed in the fields of the data set.  Each name must be followed with the designator and the designator extension ":R".  The explicit values list is not then required.

select_str_exp

is a quoted literal, a character or an alphabetic field, a function, or a concatenation of any of the preceding that evaluates to a string that represents an SQL SELECT statement used to re­trieve the values to be inserted.  This string can be built dynamically from within the Process Module.  The select_list of the SQL SELECT statement must match the explicit or implicit column_list.

HUSH

shuts off warning, error, auxiliary, and SQL messages for the execution of that statement only.  The text of the error message can be found in the system function @ERROR_MESSAGE.

Example

READY STORES
'S132' TO STORE_CODE:STORES:R
'SUPER DISCOUNT BOOK WAREHOUSE' TO STORE_NAME:STORES:R
'1234 BARGAIN BLVD.' TO STORE_ADDRESS:STORES:R
'CITY OF COMMERCE' TO CITY:STORES:R
'CA' TO STATE:STORES:R
'95123-1011' TO ZIP:STORES:R
'USA' TO COUNTRY:STORES:R
SQL INSERT INTO STORES
SQL COMMIT WORK

NOTES:  See Volume II of the ACCENT R Professional Desk Reference Set for information about the READY statement.  The system field @SQLCODE contains the return status of the SQL INSERT statement.  The system field @SQL_INSERT contains the number of rows inserted by the SQL INSERT statement.  Please note that use of the READY statement eliminates the need for a VALUES clause on the INSERT statement.

An error message is displayed if the short form of the SQL INSERT statement is used when an Oracle table has date columns with invalid values.  If there is no value in the date column (or any other column), specify a column list only for columns that have data.  ACCENT R cannot provide Oracle with a null date value.

SEE ALSO:  OSQL INSERT command.

SQL Fetch Statement    SQL Rollback Work Statement