简体   繁体   English

如何使用 MyBatis 调用 Oracle 数据库序列号?

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

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:我想使用 MyBatis 从我的 Oracle 数据库 10g 调用序列号,但我只收到如下错误消息:

ORA-02289: Sequence is not available.

How can I call a sequence number from an Oracle Database?如何从 Oracle 数据库调用序列号?

Here is my Maven Project Dependency concerning the current MyBatis Version:这是我关于当前 MyBatis 版本的 Maven 项目依赖项:

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

Here is my Dao Java class:这是我的 Dao Java 类:

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

Here is my xml declaration:这是我的 xml 声明:

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

I think you use nextval for inserting.Try following:我认为您使用 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>

Also instead of SELECT nextVal('mySeq') you can use this SELECT mySeq.nextVal from dual此外,您可以使用此SELECT mySeq.nextVal from dual而不是SELECT nextVal('mySeq')

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>

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 如何使用mybatis调用oracle存储过程(基于注释)。 - How to call oracle stored procedure using mybatis (annotation based.) 如何使用MyBatis从Oracle读取NUMBER列的“ NULL”值 - How to Read “NULL” value for a NUMBER column from Oracle using MyBatis 如何调用在MyBatis中返回Oracle记录类型的Oracle函数 - How to call Oracle function which return Oracle record type in MyBatis 使用MyBatis和Spring进行Oracle数据库轮询 - Oracle database polling with MyBatis and Spring MyBatis Oracle呼叫PLS-00306:呼叫错误的参数数量或类型错误 - MyBatis Oracle Call PLS-00306: wrong number or types of arguments in call Error 如何从oracle_database 获取序列的nextvalue 并使用oracle 10g 在netbeans 的JOptionPane 中显示它? - how to get nextvalue of sequence from oracle_database and show it in JOptionPane in netbeans using oracle 10g? 如何使用MyBatis在Oracle中获取最后一个插入ID? - How to obtain last insert id in Oracle using MyBatis? 如何使用MyBatis和Spring集成将unicode插入Oracle NVARCHAR - How to insert unicode to Oracle NVARCHAR using MyBatis with Spring integration 如何在使用oracle函数时将参数作为CLOB传递给mybatis? - How to pass arguments as CLOB in mybatis while using oracle functions? 如何用MyBatis更新数据库? - How to update database with MyBatis?
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM