What is output of this SQL where current value of sequence is 3?Select seq.curval,seq.Nextval,seq.Nextval from dual ? Give reason?

Questions by ddkdhar   answers by ddkdhar

Showing Answers 1 - 2 of 2 Answers

Nikhil_4_Oracle

  • Mar 8th, 2007
 


HI ddkdhar,

  U r output wll be...

   CURRVAL    NEXTVAL    NEXTVAL
    -----------     -----------     -----------
         3               3                3

Coz , sequence are stored objects in oracle and Incremented only when they

are use with in executable code, let Us C.....


--Seq.currval=3;

--Desc tabQ

--NUM     NUMBER(2)

  1  begin for i in 1..10
  2  loop
  3  insert into tabq values(Seq.nextval);
  4  end loop;
  5* end;
  SQL> /


 PL/SQL procedure successfully completed.

 Elapsed: 00:00:00.04
 
SQL> select * from tabq;


      NUM
----------
         4
         5
         6
         7
         8
         9
        10
        11
        12
        13


  10 rows selected.


 Elapsed: 00:00:00.16

SQL> select Seq.currval,Seq.nextval from dual;

  
CURRVAL    NEXTVAL
---------- ----------
        14         14


1 row selected.

Elapsed: 00:00:00.07
 
 Now there is no issue how many times u fire above select Query, its always 14.

 so, Is this  Clear ddkdhar.....

Regards,

Nikhil.

 

  Was this answer useful?  Yes

nikhil take 14 is the currvalue  in the sequence
the result for this query is
select s.currval , s. nextval,s.nextval from dual
is
15,15,15

yes :-) ok 
now about execution  of this query
.i have one doubt


oracle executes from right to left columns ....
then the next seq in the middle should be incremented by 1 ,


but here we arre getting
all same values .
thanks  for giving responses nikhil


.

  Was this answer useful?  Yes

Give your answer:

If you think the above answer is not correct, Please select a reason and add your answer below.

 

Related Answered Questions

 

Related Open Questions