ibatis插入数据返回ID的方法

主要就是利用seelctkey来获取这个ID值,但是oracle和mysql的区别还是很大的

oracle的用法


 <insert >

    <selectKey resultClass="long" keyProperty="Id" >

      select operation_seq.nextval as id from desc

    </selectKey>

  insert into test(id,name,desc) values (#id#,#name#,#desc#)

 </insert>


oracle主要通过序列来返回insert的ID号,所以selectkey主要做的操作是从序列中拿到下一个值


mysql的用法

 <insert >

 insert into test(ID, NAME, DESC) values (#ID#, #NAME#, #DES#)

   <selectKey resultClass="string" keyProperty="id">

     select last_insert_id() as ID from test limit 1
    </selectKey>
</insert>


msyql主要利用了last_insert_id这个函数来获取最大的id值

相关文章:

  • 2021-09-22
  • 2022-12-23
  • 2022-12-23
  • 2021-08-14
  • 2021-08-03
  • 2021-11-12
  • 2022-12-23
  • 2022-12-23
猜你喜欢
  • 2021-08-14
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
  • 2022-12-23
相关资源
相似解决方案