oracle 怎么实现LAST_INSERT_ID(mysql的函数())
                我对这个函数不太了解 
                          希望高手 给我详细解释一下  这个函数的作用  和  用法
                                    在网上看到的有一些例子 可是解释的都不太清楚 
                                               在次希望高手把源码 贴一下
             求求高手们了
      

解决方案 »

  1.   

    不懂mysql:
    Important: If you insert multiple rows using a single INSERT statement,
    LAST_INSERT_ID() returns the value generated for the first inserted row only.
      

  2.   

    这是取mysql当前连接最新执行生成自增列的值LAST_INSERT_ID。
    如果一次批量插入多个值,取的仍然是第一个值。
    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: 0mysql> 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>
      

  3.   

    oracle没有自增列,只能建一个序列来配合表来实现,
    并且使用currval只能取到序列最后的值
    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
    ----------
             1SQL> insert into t select t_seq.nextval,object_name from user_objects where rownum<=3;已创建3行。SQL> select t_seq.currval from dual;   CURRVAL
    ----------
             4SQL>