Museum

Home

Lab Overview

Retrotechnology Articles

⇒ Online Manual

Media Vault

Software Library

Restoration Projects

Artifacts Sought

Related Articles

RETURNING_DBKEY

VALUES

More Information

Examples

Positioned INSERT

List INSERT

column name

select expr

INTO parameter

UNION

More Information

select clause

ALL

col select expr

UNION

ALL

col select clause

RDB/VMS SQL INSERT — VMS RDB_4.1A

 INSERT INTO ─┬─> table-name ──────────┬────┐
              ├─> view-name ───────────┤    │
              └─>  
C

U

R

S

O

R
cursor-name ─┘ │ ┌────────────────────────────────────────┘ └┬───────────────────────────┬─┐ └─> ( ─┬> column-name ┬─> ) ┘ │ └────── , <────┘ │ ┌─────────────────────────────┘ ├─> 
V

A

L

U

E

S
──> ( ─┬┬─> literal ──────────┬┬─> ) ─┐ │ │├─> parameter ────────┤│ │ │ │├─> col-select-expr ──┤│ │ │ │├─> 
N

U

L

L
─────────────┤│ │ │ │├─> 
U

S

E

R
─────────────┤│ │ │ │├─> 
C

U

R

R

E

N

T

D

A

T

E
─────┤│ │ │ │├─> 
C

U

R

R

E

N

T

T

I

M

E
─────┤│ │ │ │└─> 
C

U

R

R

E

N

T

T

I

M

E

S

T

A

M

P
┘│ │ │ └──── , <───────────────┘ │ │ ┌───────────────────────────────────────────┘ │ └┬───────────────────────────────────┬────┬─> typebox (;) │ └─> 
R

E

T

U

R

N

I

N

G

D

B

K

E

Y
typebox (I)typebox (N)typebox (T)typebox (O) parameter ─┘ │ └──> select-expr ──────────────────────────────┘

Additional information available:

RETURNING_DBKEYVALUES

More InformationExamplesPositioned INSERTList INSERTcolumn name
select expr

More Information

 The INSERT statement stores data in the rows of a table.

 If you are storing data of data type LIST OF BYTE VARYING in
 your table, use a positioned insert to store one or more rows in
 an insert only table cursor.  The positioned insert sets up the
 proper row context for a subsequent insert list cursor.

 After establishing row context, use a list insert to store data
 in the elements of a list within that table row.

 The positioned insert and list insert require special subsets of
 the INSERT statement syntax.  For syntax, see Positioned_INSERT
 and List_INSERT.

Examples

 Example 1:  Inserting the user name and an amount into table
 columns:

 SQL> CREATE TABLE TABLE1 (ID CHAR(15),
            AMOUNT INT(4));
 SQL> INSERT INTO TABLE1 (ID, AMOUNT)
 cont> VALUES (USER, 1000);
 SQL> SELECT * FROM TABLE1;
  ID                          AMOUNT
  ELLINGSWORTH             1000.0000
 1 row selected

 Example 2:  Inserting a name and a column select expression into
 the same table columns used in the previous example:

 SQL> INSERT INTO TABLE1 (ID, AMOUNT)
 cont> VALUES ('BROWN',
 cont>        (SELECT COUNT (*) FROM TABLE1));
 SQL> SELECT * FROM TABLE1;
  ID                          AMOUNT
  HALVORSON                1000.0000
  BROWN                       1.0000
 2 rows selected

 Example 3:  Inserting a string literal that includes both single
 and double quotation marks.  Note that you must use two
 consecutive single quotation marks to output a single quotation
 mark within a string.

 SQL> CREATE TABLE TEST_TABLE (TEST_COL CHAR (22));
 SQL> INSERT INTO TEST_TABLE (TEST_COL) VALUE ('Richard -
 cont> "Rick" Smith''s');
 SQL> SELECT * FROM TEST_TABLE;
  TEST_COL
  Richard "Rick" Smith's

Positioned INSERT

 INSERT INTO CURSOR ───> cursor-name ──┐
    ┌──────────────────────────────────┘
    └─┬────────────────────────────┬───┐
      └─> ( ─┬ column-name ─┬─> ) ─┘   │
             └────── , <────┘          │
    ┌──────────────────────────────────┘
    │
    └─> 
V

A

L

U

E

S
──> ( ─┬┬─> literal ───┬┬──> ) ───>typebox (;) │├─> parameter ─┤│ │├─> 
N

U

L

L
──────┤│ │└─> 
U

S

E

R
──────┘│ └──── , <────────┘

List INSERT

 INSERT INTO CURSOR ───> cursor-name  ──┐
                                        │
   ┌────────────────────────────────────┘
   └──> 
V

A

L

U

E

S
──> ( ─┬┬─> literal ───┬┬─> ) ──> typebox (;) │└─> parameter ─┘│ └───── , <───────┘

column name

 A list of names of columns in the table or view.  You can list
 the columns in any order, but the names must correspond to those
 of the table or view.

 If you do not include all the column names in the list, SQL
 assigns a null value to those not specified, unless columns were
 defined with the NOT NULL clause in the CREATE TABLE statement.
 You must include in an INSERT statement all names of columns
 defined with the NOT NULL clause.

 Omitting the list of column names altogether is the same as
 listing all the columns of the table or view in the same order
 as they were defined.

RETURNING_DBKEY

 Returns the database key (DBKEY) of the row being added.  When
 the DBKEY value is valid, subsequent queries can use the DBKEY
 to access the record directly.

Additional information available:

INTO parameter

INTO parameter

 Inserts the database key (DBKEY) of the row to a specified
 parameter.  The INTO parameter clause is not valid in
 interactive SQL.

select expr

 select-expr =

 ─┬─┬─> select-clause ─────┬─┬────────────────────┬─┐
  │ └─>( select-expr ) ────┤ └─> order-by-clause ─┘ │
  │ ┌─────────<────────────┘                        │
  │ └─>
U

N

I

O

N
─┬───────┬────┐ │ │ └─>
A

L

L
─┘ │ │ └───────<────────────────┘ │ ┌─────────────────────────────────────────────────┘ └─┬────────────────────┬───────────────────────────> └─> limit-to-clause ─┘

Additional information available:

UNION

More Informationselect clause

More Information

 A select expression that specifies a result table.  The result
 table can contain zero or more rows.  All the rows of the result
 table are added to the target table named in the INTO clause.

 The number of columns in the result table must correspond to the
 number of columns specified in the list of column names.  If you
 did not specify a list of column names, the number of columns in
 the result table must be the same as the number of columns in
 the target table.  The value of the first column in the result
 table is assigned to the first column of the target table, the
 second value to the second column, and so on.

select clause

 select-clause =

 SELECT ─┬──────>──────┬─> select-list ──┐
         ├─> 
A

L

L
──────┤ │ └─> 
D

I

S

T

I

N

C

T
─┘ │ ┌──────────────────────────────<────────┘ └─> 
F

R

O

M
─┬┬─> table-name ─┬┬─────>─────────────┬┬─┐ │└─> view-name ──┘└> correlation-name ┘│ │ └────────── , <────────────────────────┘ │ ┌──────────────────────────────────────────────────┘ └┬─────────>────────┬┬─────────────>──────────────┬┐ └> 
W

H

E

R

E
predicate ┘└> 
G

R

O

U

P

B

Y
─┬> column-name ┬┘│ └─────── , <───┘ │ ┌────────────────────────────────<─────────────────┘ └┬──────────>──────────┬──┬────────────────────┬─┐ └─> 
H

A

V

I

N

G
predicate ─┘ └─> limit-to-clause ─┘ │ ┌────────────────────────────────────────────────┘ └┬───────────────────┬──────────────────────────────> └─> order-by-clause ┘ For more information on select expressions, see the online help topic on select_expr.

UNION

 The union operator merges the results of a select expression or
 select clause with another select expression or select clause
 into one result table by appending the values of columns in one
 table with the values of columns in other tables.

Additional information available:

ALL

ALL

 The ALL qualifier specifies that duplicate rows should not be
 eliminated from the result table.

VALUES

 The VALUES clause specifies a list of values to be added to the
 table as a single row.  The values can be specified through
 literals, parameters, column select expressions, and the
 keywords NULL, USER, CURRENT_DATE, CURRENT_TIME, or
 CURRENT_TIMESTAMP.

 The number of values in the list must correspond to the number
 of columns specified in the list of column names.  If you did
 not specify a column list, the number of values in the list must
 be the same as the number of columns in the table.  The first
 value specified in the list is assigned to the first column, the
 second value to the second, and so on.

Additional information available:

col select expr

col select expr

 col-select-expr =

 ─┬─┬─> col-select-clause ─┬─┬────────────────────┬─┐
  │ └─>( col-select-expr )─┤ └─> order-by-clause ─┘ │
  │ ┌─────────<────────────┘                        │
  │ └─> 
U

N

I

O

N
─┬───────┬────┐ │ │ └> 
A

L

L
─┘ │ │ └────────<────────────────┘ │ ┌─────────────────────────────────────────────────┘ └─┬────────────────────┬───────────────────────────> └─> limit-to-clause ─┘

Additional information available:

UNIONALL

col select clause

col select clause

 col-select-clause =

 SELECT ─┬──────>──────┬─┬─> typebox (*) ─────────────────────────────┬ 
F

R

O

M
┐ ├─> 
A

L

L
──────┤ ├─> table-name ───────┬─> .typebox (*) ──────┤ │ ├─> 
D

I

S

T

I

N

C

T
─┘ ├─> view-name ────────┤ │ │ │ ├─> correlation-name ─┘ │ │ │ └─> value-expr ────────────────────┤ │ └┬──────┬─┬───> 
S

U

M
───┬┬─> (
D

I

S

T

I

N

C

T
column-name) ┤ │ ├─> typebox (+) ─┤ ├───> 
A

V

G
───┤└─> (typebox (A)typebox (L)typebox (L) value-expr) ──────┤ │ └─> - ─┘ ├───> 
M

A

X
───┤ │ │ ├───> 
M

I

N
───┘ │ │ └───> 
C

O

U

N

T
─┬──> (typebox (*)) ───────────────────┤ │ └──> (
D

I

S

T

I

N

C

T
column-name) ┘ │ ┌────────────────────────────────<──────────────────────────────┘ └┬┬─> table-name ┬┬────────────────────┬┬─┬────────>───────────┬┐ │└─> view-name ─┘└─> correlation-name ┘│ └─> 
W

H

E

R

E
predicate ─┘│ └────────── , <────────────────────────┘ │ ┌──────────────────────────────<────────────────────────────────┘ └┬─────────────>──────────────────┬─┬──────────>──────────┬──> └─> 
G

R

O

U

P

B

Y
─┬─> column-name ─┬─┘ └─> 
H

A

V

I

N

G
predicate ─┘ └─────── , <─────┘

UNION

 The UNION operator merges the results of a select expression or
 select clause with another select expression or select clause
 into one result table by appending the values of columns in one
 table with the values of columns in other tables.

ALL

 The ALL qualifier specifies that duplicate rows should not be
 eliminated from the result table.

Typewritten Software • bear@typewritten.org • Edmonds, WA 98026