Click here to Skip to main content
15,896,118 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i have to get the next value in a sequence.....
i have created this procedure which has been created successfully but when i give it a call it give me errors...
ORA-00900 invalid sql statement
ORA-06512 at "system.next_val" at line 7

please can anyone help me.....

////procedure
SQL
create or replace procedure next_value (seqname varchar2)
as

nextvalue integer;
stat varchar2(100);

begin

stat := 'select '|| seqname||'.nextval from dual';

execute immediate stat into nextvalue;

dbms_output.put_line('Next value is: '||TO_CHAR(nextvalue));

end;


call to procedure

SQL
begin
next_value('dept');
end;
Posted
Updated 22-Nov-14 16:40pm
v3
Comments
Jörgen Andersson 23-Nov-14 10:02am    
Have you created the sequence called 'dept'?
Member 10740412 23-Nov-14 17:57pm    
yep

The question is to vague to answer it. I'd suggest to read this:
ORA-06512[^]
ORA-00900[^]
 
Share this answer
 
hi Member 10740412,
When I had executed the same code for the first time, got the same errors. We will get those errors if the sequence was not created in that schema where the procedure was executed.
I will suggest you some logic this may resolve your problem .We will use dynamic programing for that procedure

1. First check whether the sequence exist or not if not exist then automatically create the sequence otherwise it will exit the block.

2. After that block do the operations


after creation of this procedure now execute with your example

3.Test the code with an example

let me know how you check those block

regards
Smart003
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900