If this is your first visit, be sure to check out the FAQ by clicking the link above. You may have to register before you can post: click the register link above to proceed. To start viewing messages, select the forum that you want to visit from the selection below.

 
Go Back  dBforums > Data Access, Manipulation & Batch Languages > ANSI SQL > How do i get seq.nextval from within a pl/sql function

Reply
 
LinkBack Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old 02-18-04, 17:57
ljordan ljordan is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
Question How do i get seq.nextval from within a pl/sql function

Hi,

Im using Oracle 9i and writing a PL/SQL function and i need to get the sequence.nextval within the function. I am getting an error saying sequence does not exist. I have tryed the following :

select mySeq.nextval
into v_myvar
from dual;

but I still get the same error message. Is there any way to get the next value in a sequence from within a PL/SQL function.

Any help would be greatly appreciated.
Thanks
Reply With Quote
  #2 (permalink)  
Old 02-19-04, 03:20
Littlefoot Littlefoot is offline
Lost Boy
 
Join Date: Jan 2004
Location: Croatia, Europe
Posts: 3,629
PHP Code:
CREATE SEQUENCE myseq;

CREATE OR REPLACE FUNCTION fun_seq
   
RETURN NUMBER
AS
   
retval   NUMBER;
BEGIN
   SELECT myseq
.NEXTVAL
     INTO retval
     FROM DUAL
;

   RETURN (
retval);
END;
/

SELECT fun_seq FROM DUAL;

FUN_SEQ
-------
      

Reply With Quote
  #3 (permalink)  
Old 02-19-04, 08:11
ljordan ljordan is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
Hi,
Thanks. I dont need to create a sequence because the sequence that I am using (mySeq) already exists on the database.

Thanks
Reply With Quote
  #4 (permalink)  
Old 02-19-04, 16:04
ljordan ljordan is offline
Registered User
 
Join Date: Feb 2004
Posts: 6
Figured it out. It was a permissions issue.
Reply With Quote
Reply

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On