12
返回列表 发新帖
楼主: yanggq

[Q]如何知道sequenc的nextval而不用sequencename.nextval

[复制链接]
论坛徽章:
86
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-01-04 11:49:542012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:202012新春纪念徽章
日期:2012-02-13 15:13:20咸鸭蛋
日期:2012-05-08 10:27:19版主8段
日期:2012-05-15 15:24:112013年新春福章
日期:2013-02-25 14:51:24
11#
发表于 2004-12-14 09:24 | 只看该作者
1:如果有多个进程可能操作这个序列这就是没多大意义的
2:序列不断号几乎是不大可能的,很难保证,包括数据库重新启动(不cache又可能有性能问题)、shared pool  age out 等等因素
3:你的序列看样子increment是5 ?

使用道具 举报

回复
论坛徽章:
2
会员2006贡献徽章
日期:2006-04-17 13:46:342011新春纪念徽章
日期:2011-02-18 11:42:48
12#
发表于 2004-12-14 09:26 | 只看该作者

asktom

使用道具 举报

回复
招聘 : 系统架构师
论坛徽章:
372
双子座
日期:2015-08-18 12:18:21摩羯座
日期:2015-09-20 17:10:27秀才
日期:2015-09-21 09:46:16秀才
日期:2015-09-21 11:16:42秀才
日期:2015-10-08 17:57:58天枰座
日期:2015-10-28 18:28:29秀才
日期:2015-11-11 09:48:44秀才
日期:2015-11-11 10:07:14秀才
日期:2015-11-11 10:22:49秀才
日期:2015-09-11 10:43:06
13#
 楼主| 发表于 2004-12-14 09:28 | 只看该作者
1.是多个进程操作这个序列,但是不想丢太多,因为曾经发生过sequece out of number 的问题
3.是的,increment 是5.因为需要复制到别的库中,所以本库start with 2, increment by 5.

使用道具 举报

回复
招聘 : 系统架构师
论坛徽章:
372
双子座
日期:2015-08-18 12:18:21摩羯座
日期:2015-09-20 17:10:27秀才
日期:2015-09-21 09:46:16秀才
日期:2015-09-21 11:16:42秀才
日期:2015-10-08 17:57:58天枰座
日期:2015-10-28 18:28:29秀才
日期:2015-11-11 09:48:44秀才
日期:2015-11-11 10:07:14秀才
日期:2015-11-11 10:22:49秀才
日期:2015-09-11 10:43:06
14#
 楼主| 发表于 2004-12-14 09:34 | 只看该作者
Great!!!
I want to select the current value from a sequence.

When i do : select <seq.name>.currval from dual

ORA-08002 error is appearing.  
sequence %s.CURRVAL is not yet defined in this session

How to avoid this..

If i do : select <>.nextval from dual,  then the value is
changed from the sequence.  After that the currval is working.
But if i disconnect that session and again connect to that
session i am facing the error.

Other ways (Workaround ..):

1)  i can take the value from dba_sequences (last_number-1).

2)  I tried to alter the sequence with nocache.  Eventhough
    it is not working..

Can u help me to solve this issue.

Awaiting for your valuable suggesstion.

Thanking you

With best regards
Ravindar S.



and we said...

Currval is by definition the value returned by your sessions last call to
nextval.  If your session has not called Nextval yet, Currval is undefined.

The value in dba_sequences will typically not suffice to find what the nextval
would be if you selected it as the last_number in dba_sequences jumps by the
cache size.  If you set the NOCACHE option (not recommended, it'll just make
things slow), then last_number will return what nextval would have returned had
you invoked it.

Since on an active system, whatever you get from dba_sequences is "stale" or out
of date almost as soon as you get it (others will be selecting nextval all of
the time) what I recommend is that you use either

  last_number
  last_number-cache_size+1

from dba_sequences.  Either is a good approximation of what the Nextval would be
(and all options to you are approximiations)...


   Reviews      
GOTO a page to Bookmark Review | Bottom | Top
Getting NextVal from Dynamic Performance View  November 17, 2002
Reviewer:  Pablo Rovedo  from Argentina

Tom:

  You can get the nextval through the dynamic performance  
  view sys.v$_sequences.
  
Connecting with sys

sys@ROP816> desc v$_sequences
Name                                                  Null?    Type
----------------------------------------------------- --------
------------------------------
SEQUENCE_OWNER                                                 VARCHAR2(64)
SEQUENCE_NAME                                                  VARCHAR2(1000)
OBJECT#                                                        NUMBER
ACTIVE_FLAG                                                    VARCHAR2(1)
REPLENISH_FLAG                                                 VARCHAR2(1)
WRAP_FLAG                                                      VARCHAR2(1)
NEXTVALUE                                                      NUMBER
MIN_VALUE                                                      NUMBER
MAX_VALUE                                                      NUMBER
INCREMENT_BY                                                   NUMBER
CYCLE_FLAG                                                     VARCHAR2(1)
ORDER_FLAG                                                     VARCHAR2(1)
CACHE_SIZE                                                     NUMBER
HIGHWATER                                                      NUMBER
BACKGROUND_INSTANCE_LOCK                                       VARCHAR2(1)
INSTANCE_LOCK_FLAGS                                            NUMBER

sys@ROP816> create view v$sequences as select * from v$_sequences;

View created.

sys@ROP816> create public synonym v$sequences for sys.v$sequences;

Synonym created.

sys@ROP816> grant select on v$sequences to public;

Grant succeeded.

sys@ROP816>

and then connect with any user

rop@ROP816> create sequence s1_seq;

Sequence created.

rop@ROP816> select s1_seq.nextval from dual;

   NEXTVAL
----------
         1

rop@ROP816> select b.object_name,a.nextvalue
  2  from v$sequences a, user_objects b
  3  where a.object# = b.object_id and
  4        b.object_name = 'S1_SEQ'
  5  /

OBJECT_NAME           NEXTVALUE
-------------------- ----------
S1_SEQ                        2

rop@ROP816> select s1_seq.nextval from dual;

   NEXTVAL
----------
         2

rop@ROP816> select b.object_name,a.nextvalue
  2  from v$sequences a, user_objects b
  3  where a.object# = b.object_id and
  4        b.object_name = 'S1_SEQ'
  5  /

OBJECT_NAME           NEXTVALUE
-------------------- ----------
S1_SEQ                        3

rop@ROP816>

Regards
Pablo A. Rovedo

PD: I have read your book twice, is excellent!!!
    Are you writing a new one? any book regarding     
    performance would by great

使用道具 举报

回复
招聘 : 系统架构师
论坛徽章:
372
双子座
日期:2015-08-18 12:18:21摩羯座
日期:2015-09-20 17:10:27秀才
日期:2015-09-21 09:46:16秀才
日期:2015-09-21 11:16:42秀才
日期:2015-10-08 17:57:58天枰座
日期:2015-10-28 18:28:29秀才
日期:2015-11-11 09:48:44秀才
日期:2015-11-11 10:07:14秀才
日期:2015-11-11 10:22:49秀才
日期:2015-09-11 10:43:06
15#
 楼主| 发表于 2004-12-14 09:36 | 只看该作者

Re: asktom



谢谢melocy兄

使用道具 举报

回复
论坛徽章:
27
ITPUB元老
日期:2005-02-28 12:57:002012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:182012新春纪念徽章
日期:2012-02-13 15:11:18马上有车
日期:2014-02-19 11:55:14马上有房
日期:2014-02-19 11:55:14马上有钱
日期:2014-02-19 11:55:14马上有对象
日期:2014-02-19 11:55:142012新春纪念徽章
日期:2012-02-13 15:11:18
16#
发表于 2004-12-14 09:37 | 只看该作者

Re: [Q]如何知道sequenc的nextval而不用sequencename.nextval

可以换个思路:

从使用sequence的业务表中查, 难道不是很方便吗?

使用道具 举报

回复
招聘 : 系统架构师
论坛徽章:
372
双子座
日期:2015-08-18 12:18:21摩羯座
日期:2015-09-20 17:10:27秀才
日期:2015-09-21 09:46:16秀才
日期:2015-09-21 11:16:42秀才
日期:2015-10-08 17:57:58天枰座
日期:2015-10-28 18:28:29秀才
日期:2015-11-11 09:48:44秀才
日期:2015-11-11 10:07:14秀才
日期:2015-11-11 10:22:49秀才
日期:2015-09-11 10:43:06
17#
 楼主| 发表于 2004-12-14 09:38 | 只看该作者

Re: Re: [Q]如何知道sequenc的nextval而不用sequencename.nextval

最初由 oldwain 发布
[B]可以换个思路:

从使用sequence的业务表中查, 难道不是很方便吗? [/B]

NOT a good idea as I expect.

使用道具 举报

回复
论坛徽章:
2
会员2006贡献徽章
日期:2006-04-17 13:46:342011新春纪念徽章
日期:2011-02-18 11:42:48
18#
发表于 2004-12-14 09:39 | 只看该作者
要感谢的应该是 Tom

使用道具 举报

回复

您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

TOP技术积分榜 社区积分榜 徽章 团队 统计 知识索引树 积分竞拍 文本模式 帮助
  ITPUB首页 | ITPUB论坛 | 数据库技术 | 企业信息化 | 开发技术 | 微软技术 | 软件工程与项目管理 | IBM技术园地 | 行业纵向讨论 | IT招聘 | IT文档
  ChinaUnix | ChinaUnix博客 | ChinaUnix论坛
CopyRight 1999-2011 itpub.net All Right Reserved. 北京盛拓优讯信息技术有限公司版权所有 联系我们 未成年人举报专区 
京ICP备16024965号-8  北京市公安局海淀分局网监中心备案编号:11010802021510 广播电视节目制作经营许可证:编号(京)字第1149号
  
快速回复 返回顶部 返回列表