17,086
社区成员
发帖
与我相关
我的任务
分享
SQL> create table t (id int, name varchar2(20));
表已创建。
SQL> create sequence t_seq start with 1;
序列已创建。
SQL> insert into t values(t_seq.nextval,'tom');
已创建 1 行。
SQL> select t_seq.currval from dual;
CURRVAL
----------
1
SQL> insert into t select t_seq.nextval,object_name from user_objects where rownum<=3;
已创建3行。
SQL> select t_seq.currval from dual;
CURRVAL
----------
4
SQL>
mysql> create table t(id int auto_increment primary key,name varchar
Query OK, 0 rows affected (0.41 sec)
mysql> insert into t(name) values('tom');
Query OK, 1 row affected (0.03 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 1 |
+------------------+
1 row in set (0.00 sec)
mysql> insert into t(name) values('kyte');
Query OK, 1 row affected (0.03 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 2 |
+------------------+
1 row in set (0.00 sec)
mysql> insert into t(name) values('bob'),('white'),('jerry');
Query OK, 3 rows affected (0.01 sec)
Records: 3 Duplicates: 0 Warnings: 0
mysql> select * from t;
+----+-------+
| id | name |
+----+-------+
| 1 | tom |
| 2 | kyte |
| 3 | bob |
| 4 | white |
| 5 | jerry |
+----+-------+
5 rows in set (0.00 sec)
mysql> select last_insert_id();
+------------------+
| last_insert_id() |
+------------------+
| 3 |
+------------------+
1 row in set (0.00 sec)
mysql>