Get primary KEY (Oracle trigger vs. seq) when Mybatis insert operation

Source: Internet
Author: User

1. Through the Oracle sequence

    1. --Create sequence
    2. Create sequence Seq_dw_ewsystem
    3. MinValue 1
    4. MaxValue 999999999999999999999999999
    5. Start with 1
    6. Increment by 1
    7. Cache 20;
  1. <insert id="Insertewsystem" parametertype="Ewsystem">
  2. <selectkey keyproperty="id" resulttype="Long" order="before">
  3. SELECT Seq_ewsystem. Nextval from DUAL <!--SELECT DECODE (MAX (ID), Null,0,max (ID)) +1 from Ewsystem--
  4. </selectkey>
  5. INSERT into Ewsystem (id,org_id,name) VALUES (#{id},#{orgid,jdbctype=varchar},#{name,jdbctype= VARCHAR})
  6. </Insert>

2. Through Oracle triggers

    1. create or  replace trigger trg_dw_ewsystem  
    2.  before insert 
    3. on dw_ewsystem  FOR&NBSP;EACH&NBSP;ROW&NBSP;
    4. begin  
    5. Select seq_dw_ewsystem.nextval into :new.id  from dual; 
    6. end; 
    1. <insert id="Insertewsystem" parametertype="Ewsystem">
    2. <selectkey resulttype="int" keyproperty="id" order="after">
    3. SELECT seq_dw_Ewsystem. Currval from DUAL
    4. </selectkey>
    5. INSERT into Ewsystem (id,org_id,name) VALUES (#{id},#{orgid,jdbctype=varchar},#{name,jdbctype= VARCHAR})
    6. </Insert>

Get primary KEY (Oracle trigger vs. seq) when Mybatis insert operation

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.