| |
 |
|
Oracle Tips by Burleson |
INSERT
In all the examples in this book, we have
been pulling data from the PUBS schema which was loaded using the
pubs_db.sql script in the code depot. This script created all our
tables and loaded all the practice data. To load the data in the
tables, it used the INSERT statement. Below are a few lines from
the script loading data into the book_author table.
--*****************************************
-- Insert book_author (25 rows)
--*****************************************
INSERT INTO BOOK_AUTHOR VALUES ('A101',
'B101', .11);
INSERT INTO BOOK_AUTHOR VALUES ('A102',
'B101', .08);
INSERT INTO BOOK_AUTHOR VALUES ('A103',
'B102', .12);
INSERT INTO BOOK_AUTHOR VALUES ('A104',
'B102', .15);
INSERT INTO BOOK_AUTHOR VALUES ('A105',
'B103', .10);
INSERT INTO BOOK_AUTHOR VALUES ('A109',
'B104', .12);
INSERT INTO BOOK_AUTHOR VALUES ('A110',
'B105', .13);
INSERT INTO BOOK_AUTHOR VALUES ('A104',
'B106', .16);
Each statement loads one row of data. The
basic statement is:
insert into <table name> (col1, col2,
col3,…)
values (val1, val2,
val3,…);
If the values listed are in the same order
as the table columns and there is a value (even if it is NULL) for
each column, you can leave out the column list as in the example
above. The easiest way to determine which columns are in the table
is to describe the table (SQL> desc author) as we have been doing in
our examples. If you exclude a column from the INSERT, then the
column list is mandatory because the database needs to match the
values to the columns. Excluded columns will contain NULL unless
the table has a default value defined for that column. First, let’s
insert a new row in the SALES table.
SQL> insert into sales values (
2 'S124',
3 'B124',
4 'O504',
5 to_date ('01-02-2005
14:30','MM-DD-YYYY HH24:MI'),
6 100);
1 row created.
This INSERT statement has a value for each
column, and they are ordered the same as the table.
The above book excerpt is from:
Easy Oracle
SQL
Get Started
Fast writing SQL Reports with SQL*Plus
ISBN 0-9727513-7-8
Col. John Garmany
http://www.rampant-books.com/book_2005_1_easy_sql.htm |