sequence与会话有关--oracle一个比较烂的特性

如果刚刚打开一个会话 ,例如用PL/SQL developer打开一个command窗口
执行一个
SQL> create sequence seq_test_id start with 1;

Sequence created

SQL> select seq_test_id.currval from dual;

select seq_test_id.currval from dual

ORA-08002: sequence SEQ_TEST_ID.CURRVAL is not yet defined in this session

这时会告诉你 sequence SEQ_TEST_ID.CURRVAL is not yet defined in this session
显然SEQ_TEST_ID当前是存在的,而其sequence对象应该也和session无关.


如何解决这个问题 呢 ??
只需要执行
SQL> select seq_test_id.nextval from dual;

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

SQL> select seq_test_id.currval from dual;

   CURRVAL
----------
         1

原来在查看sequence对象的currval值的时候,必须先要调用它的nextval,实在是没道理的很把,可oracle就是如此??
oracle乐于无端增加学习成本阿 /呵呵

只要新打开一个command的窗口,也就会有类似问题,所以记住这个特性就够啦

oracle的错误码也有官方表达

ORA-08002: sequence string.CURRVAL is not yet defined in this session
Cause: sequence CURRVAL has been selected before sequence NEXTVAL
Action: select NEXTVAL from the sequence before selecting CURRVAL


Trackback: http://tb.blog.csdn.net/TrackBack.aspx?PostId=1446746

 

你可能感兴趣的:(oracle,sql,.net,Blog)