[英]How to call oracle stored procedure using mybatis (annotation based.)
[英]How to call a Oracle database sequence number by using MyBatis?
我想使用 MyBatis 從我的 Oracle 數據庫 10g 調用序列號,但我只收到如下錯誤消息:
ORA-02289: Sequence is not available.
如何從 Oracle 數據庫調用序列號?
這是我關於當前 MyBatis 版本的 Maven 項目依賴項:
<dependency>
<groupId>org.mybatis</groupId>
<artifactId>mybatis-spring</artifactId>
<version>1.1.1</version>
</dependency>
這是我的 Dao Java 類:
long mySeqNumber = myDaoClass.getNewNumber(); // here I get an exception
這是我的 xml 聲明:
<select id="getNewNumber" resultType="java.lang.Long" >
SELECT mySeq.nextval
FROM dual
</select>
我認為您使用 nextval 進行插入。嘗試以下操作:
<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>
此外,您可以使用此SELECT mySeq.nextVal from dual
而不是SELECT nextVal('mySeq')
我能夠做到這一點,
<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>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.