How to call a Oracle database sequence number by using MyBatis?

前端 未结 2 742
说谎
说谎 2021-01-24 13:08

I want to call a sequence number from my Oracle Database 10g by using MyBatis, but I only get an error message like the following:

ORA-02289: Sequence is not av         


        
相关标签:
2条回答
  • I think you use nextval for inserting.Try following:

    <insert id="insertPerson" parameterType="Person" useGeneratedKeys="true"> 
      <selectKey keyProperty="personId" resultType="int" order="BEFORE">
        SELECT nextVal('mySeq')
      </selectKey>
      INSERT INTO person (personId,PersonName) VALUES (#{personId},#{personName}) 
    </insert>
    

    Also instead of SELECT nextVal('mySeq') you can use this SELECT mySeq.nextVal from dual

    0 讨论(0)
  • 2021-01-24 13:38

    I was able to achieve this,

    <dependency>
            <groupId>org.mybatis</groupId>
            <artifactId>mybatis</artifactId>
            <version>3.5.2</version>
        </dependency> 
    
    
    
    <select id="getUploadId" resultType="int">
        select {schema}.SEQUENCE_NAME.NEXTVAL from dual
    </select>
    
    0 讨论(0)
提交回复
热议问题