从oracle序列中获取hibernate [英] Get from oracle sequence with hibernate

查看:120
本文介绍了从oracle序列中获取hibernate的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用hibernate和oracle 10 db。我需要从表中获取下一个序列值,并且想知道如何。
我看到这篇文章,并问:有没有更好的方式获取值,而不定义查询?



谢谢!

没有。从序列中获取下一个( nextval )或当前( currval )值通常使用select进行。即使在PLSQL中,使用SELECT INTO也是如此:

  SELECT YourSequence.NextVal INTO:new.ID FROM DUAL; 

这样的简单分配不起作用:

 :new.ID:= YourSeqence.NextVal; 


I am working with hibernate, and a oracle 10 db. I need to get the next sequence value from a table, and want to know how. I saw this article, and asking: is there a better way the get the value, without defining a query?

Thanks!

解决方案

No. Getting the next (nextval) or current (currval) value from a sequence is typically done using a select. Even in PLSQL, SELECT INTO is used, like this:

SELECT YourSequence.NextVal INTO :new.ID FROM DUAL;

Simple assignment like this won't work:

:new.ID := YourSeqence.NextVal;

这篇关于从oracle序列中获取hibernate的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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