如何使用MyBatis调用Oracle数据库序列号? [英] How to call a Oracle database sequence number by using MyBatis?

查看:586
本文介绍了如何使用MyBatis调用Oracle数据库序列号?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用MyBatis从Oracle数据库10g中调用序列号,但是我只收到如下错误消息:

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 available.

如何从Oracle数据库中调用序列号?

How can I call a sequence number from an Oracle Database?

这是我与当前MyBatis版本有关的Maven项目依赖项:

Here is my Maven Project Dependency concerning the current MyBatis Version:

<dependency>
   <groupId>org.mybatis</groupId>
   <artifactId>mybatis-spring</artifactId>
   <version>1.1.1</version>
</dependency>

这是我的Dao Java课:

Here is my Dao Java class:

long mySeqNumber = myDaoClass.getNewNumber(); // here I get an exception

这是我的xml声明:

<select id="getNewNumber" resultType="java.lang.Long" >
    SELECT mySeq.nextval
    FROM dual
</select>

推荐答案

我认为您使用nextval进行插入.请尝试以下操作:

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>

也可以使用SELECT mySeq.nextVal from dual

这篇关于如何使用MyBatis调用Oracle数据库序列号?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆