Oracle 5.0 Reference Manual page 1086

Table of Contents

Advertisement

form inserts rows selected from another table or tables.
Section 13.2.5.1,
"INSERT ... SELECT
You can use
REPLACE
in the treatment of new rows that contain unique key values that duplicate old rows: The new
IGNORE
rows are used to replace the old rows rather than being discarded. See
Syntax".
is the table into which rows should be inserted. The columns for which the statement
tbl_name
provides values can be specified as follows:
• You can provide a comma-separated list of column names following the table name. In this case, a
value for each named column must be provided by the
• If you do not specify a list of column names for
values for every column in the table must be provided by the
you do not know the order of the columns in the table, use
• The
clause indicates the column names explicitly.
SET
Column values can be given in several ways:
• If you are not running in strict SQL mode, any column not explicitly given a value is set to its default
(explicit or implicit) value. For example, if you specify a column list that does not name all the
columns in the table, unnamed columns are set to their default values. Default value assignment is
described in
Section 11.1.7, "Data Type Default
Invalid
Data".
If you want an
INSERT
columns that do not have a default value, you should use strict mode. See
SQL
Modes".
• Use the keyword
DEFAULT
write
statements that assign values to all but a few columns, because it enables you to
INSERT
avoid writing an incomplete
Otherwise, you would have to write out the list of column names corresponding to each value in the
list.
VALUES
You can also use
DEFAULT(col_name)
expressions to produce a given column's default value.
• If both the column list and the
its default value:
INSERT INTO
tbl_name
In strict mode, an error occurs if any column doesn't have a default value. Otherwise, MySQL uses
the implicit default value for any column that does not have an explicitly defined default.
• You can specify an expression
if the type of the expression does not match the type of the column, and conversion of a given value
can result in different inserted values depending on the data type. For example, inserting the string
into an INT, FLOAT, DECIMAL(10,6), or
'1999.0e-2'
19.9921, 19.992100, and
and
columns is
INT
YEAR
initial part of the string as may be considered a valid integer or year. For the floating-point and fixed-
point columns, the string-to-floating-point conversion considers the entire string a valid floating-point
value.
An expression
expr
do this because the value for
INSERT
Syntax".
instead of
to overwrite old rows.
INSERT
statement to generate an error unless you explicitly specify values for all
to set a column explicitly to its default value. This makes it easier to
list that does not include a value for each column in the table.
VALUES
[965]
list are empty,
VALUES
() VALUES();
to provide a column value. This might involve type conversion
expr
being inserted, respectively. The reason the value stored in the
1999
is that the string-to-integer conversion looks only at as much of the
1999
can refer to any column that was set earlier in a value list. For example, you can
refers to col1, which has previously been assigned:
col2
1066
Syntax
INSERT ... SELECT
REPLACE
list or the
VALUES
INSERT ... VALUES
VALUES
DESCRIBE tbl_name
Values". See also
Section 1.8.6.3, "Constraints on
as a more general form that can be used in
creates a row with each column set to
INSERT
column results in the values 1999,
YEAR
is discussed further in
is the counterpart to
Section 13.2.7,
"REPLACE
statement.
SELECT
or
INSERT ...
SELECT,
list or the
statement. If
SELECT
to find out.
Section 5.1.7, "Server
INSERT

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents