Database Reference
In-Depth Information
Figure 15.7
Single Table
INSERT
Command Syntax.
15.3.1
Inserting One Row
Let's start with an easy example, adding a single row to the INSTRU-
MENT table.
INSERT INTO INSTRUMENT
VALUES (INSTRUMENT_ID_SEQ.NEXTVAL
,(SELECT INSTRUMENT_ID FROM INSTRUMENT
WHERE NAME = 'String')
, 'Harp');
You do not need to list what value goes into which column if you list the
values in the same order as columns appear in the table, and all table col-
umns are filled. In this case, there are only three columns to worry about.
The first column uses a sequence that generates a number that is used as
the unique identifier for the instrument. See Chapter 22 for details on
sequences. The NEXTVAL function always returns the next available value
from a sequence. The second column finds the strings section in the
INSTRUMENTS table, the same table. The third column adds a new
instrument name.
Here is an example in which you list the columns in a different order
than they appear in the table, additionally omitting columns.
INSERT INTO MUSICCD (MUSICCD_ID, TITLE, PLAYING_TIME)
VALUES (MUSICCD_ID_SEQ.NEXTVAL, 'SPIDER-MAN','60:35');
 
Search WWH ::




Custom Search