zoukankan      html  css  js  c++  java
  • 当 LAST_INSERT_ID() 带有参数时# 清空重来

    [root@yejr.me]> truncate table t;

    # 插入1条新记录
    [root@yejr.me]> insert into t select 0,rand()*1024;

    # 查看 last_insert_id(), 符合预期
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    | 1 |
    +------------------+

    [root@yejr.me]> select * from t;
    +----+-----+
    | id | c1 |
    +----+-----+
    | 1 | 730 |
    +----+-----+

    # 调用 last_insert_id() 时增加表达式
    [root@yejr.me]> select last_insert_id(id+2) from t;
    +----------------------+
    | last_insert_id(id+2) |
    +----------------------+
    | 3 |
    +----------------------+

    # 再看 last_insert_id() 的值,好像“又不符合预期”了
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id() |
    +------------------+
    | 3 |
    +------------------+

    # 插入1条新纪录
    [root@yejr.me]> insert into t select 0,rand()*1024;

    # 再看 last_insert_id() 的值,好像“又回到正轨”了
    [root@yejr.me]> select last_insert_id();
    +------------------+
    | last_insert_id(http://www.amjmh.com) |
    +------------------+
    | 2 |
    +------------------+

    [root@yejr.me]> select * from t;
    +----+-----+
    | id | c1 |
    +----+-----+
    | 1 | 730 |
    | 2 | 600 |
    +----+-----+
    2 rows in set (0.00 sec)

  • 相关阅读:
    double相加(減)结果会有些误差
    创建表,操作表
    删除数据库
    DDL语句
    HCDA-12-配置基本静态路由
    HCDA-11-配置直连路由
    1-5配置STelnet登录系统
    HCDA-9-管理设备文件系统
    HCDA-8-了解设备系统文件
    Java生成随机汉字
  • 原文地址:https://www.cnblogs.com/ly570/p/11448345.html
Copyright © 2011-2022 走看看