Oracle 5.0 Reference Manual page 983

Table of Contents

Advertisement

1 row in set (0.00 sec)
Although the second
first of these rows was 2, and it is this value that is returned by
following
statement.
SELECT
If you use
INSERT IGNORE
incremented and
LAST_INSERT_ID()
If
is given as an argument to
expr
argument is returned by the function and is remembered as the next value to be returned by
LAST_INSERT_ID()
1. Create a table to hold the sequence counter and initialize it:
mysql>
CREATE TABLE sequence (id INT NOT NULL);
mysql>
INSERT INTO sequence VALUES (0);
2. Use the table to generate sequence numbers like this:
mysql>
UPDATE sequence SET id=LAST_INSERT_ID(id+1);
mysql>
SELECT LAST_INSERT_ID();
The
statement increments the sequence counter and causes the next call to
UPDATE
LAST_INSERT_ID()
that value. The
mysql_insert_id()
Section 20.6.6.37,
You can generate sequences without calling
function this way is that the ID value is maintained in the server as the last automatically generated
value. It is multi-user safe because multiple clients can issue the
own sequence value with the
being affected by other clients that generate their own sequence values.
Note that
mysql_insert_id()
cannot use the C API function to retrieve the value for
executing other SQL statements like
[963]
ROW_COUNT()
[963]
ROW_COUNT()
statement if it was an UPDATE, DELETE, or INSERT. For other statements, the value may not be
meaningful.
For
statements, the affected-rows value by default is the number of rows actually changed.
UPDATE
If you specify the
CLIENT_FOUND_ROWS
mysqld, the affected-rows value is the number of rows "found"; that is, matched by the
clause.
For
statements, the affected-rows value is 2 if the new row replaced an old row, because in
REPLACE
this case, one row was inserted after the duplicate was deleted.
For
INSERT ... ON DUPLICATE KEY UPDATE
is inserted as a new row and 2 if an existing row is updated.
The
[963]
ROW_COUNT()
function and the row count that the
mysql>
INSERT INTO t VALUES(1),(2),(3);
Query OK, 3 rows affected (0.00 sec)
Records: 3
Duplicates: 0
mysql>
SELECT ROW_COUNT();
Information Functions
statement inserted three new rows into t, the ID generated for the
INSERT
and the row is ignored, the
[961]
LAST_INSERT_ID()
[961]. This can be used to simulate sequences:
[961]
to return the updated value. The
C API function can also be used to get the value. See
"mysql_insert_id()".
statement (or mysql_insert_id()), without affecting or
SELECT
is only updated after
SELECT
returns the number of rows changed, deleted, or inserted by the last
flag to
value is similar to the value from the
client displays following statement execution.
mysql
Warnings: 0
963
LAST_INSERT_ID()
AUTO_INCREMENT
returns 0, which reflects that no row was inserted.
[961], the value of the
SELECT
[961], but the utility of using the
LAST_INSERT_ID()
UPDATE
and
INSERT
UPDATE
LAST_INSERT_ID(expr)
or SET.
mysql_real_connect()
statements, the affected-rows value is 1 if the row
mysql_affected_rows()
[961]
for the
counter is not
statement retrieves
statement and get their
statements, so you
[961]
after
when connecting to
WHERE
C API

Advertisement

Table of Contents
loading

This manual is also suitable for:

Mysql 5.0

Table of Contents