zoukankan      html  css  js  c++  java
  • myBatis oracle 与mysql自增问题

    mysql

     <insert id="insert" parameterType="Person" useGeneratedKeys="true" keyProperty="id">
            insert into person(name,pswd) values(#{name},#{pswd})
        </insert>

        <insert id="insert" parameterType="Person">
            <selectKey keyProperty="id" resultType="long">
                select LAST_INSERT_ID()
            </selectKey>
            insert into person(name,pswd) values(#{name},#{pswd})
        </insert>

    oracle

    CREATE SEQUENCE  "SEQ_M_USER" 

    MINVALUE 1

    MAXVALUE 9999999999999999999999999999

    INCREMENT BY 1 START WITH 501 CACHE 20 ORDER  NOCYCLE ;

    1.先通过sequence查出来id,再insert

    <insert id=”add” useGeneratedKeys=”false” keyProperty=”id” parameterType=”Person”>
    <selectKey resultType=”String”  keyProperty=”id” order=”BEFORE”>
    select yoursequence.nextval as id from dual
    </selectKey>
    insert into Person (id,user_id, user_name) values(#{id},#{userid},#{username})
    </insert>

    2.直接insertsequence.nextval,如下

    <insert id=”add” useGeneratedKeys=”false” keyProperty=”id” parameterType=”Person”>
    insert into Person (id,user_id, user_name) values(yoursequence.nextval,#{userid},#{username})
    </insert>
  • 相关阅读:
    SpringBoot2 application.properties方式加载配置文件
    php第三十节课
    php第二十九节课
    php第二十八节课
    php第二十七节课
    php第二十六节课
    php第二十五节课
    php第二十四节课
    DBDA
    php第二十三节课
  • 原文地址:https://www.cnblogs.com/zhangmu126/p/5403306.html
Copyright © 2011-2022 走看看