如何获取序列中的下一个值? [英] how to get the next value in a sequence?

查看:668
本文介绍了如何获取序列中的下一个值?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我必须得到一个序列中的下一个值.....

i创建了这个已经成功创建的程序但是当我给它打电话时它会给我错误...

ORA-00900无效的sql语句

ORA-06512在第7行的system.next_val



please任何人都可以帮助我.....



////程序

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

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

begin
next_value('dept');
end;

推荐答案

问题是含糊不清回答问题。我建议你阅读这个:

ORA-06512 [ ^ ]

ORA-00900 [ ^ ]
The question is to vague to answer it. I'd suggest to read this:
ORA-06512[^]
ORA-00900[^]


hi Member 10740412,

当我执行相同的代码时这是第一次出现同样的错误。如果序列没有在执行过程的模式中创建,我们将得到这些错误。

我会建议你一些逻辑可以解决你的问题。我们将使用动态编程用于该程序



1。首先检查序列是否存在(如果不存在)然后自动创建序列,否则它将退出块。



2.在该块之后执行操作




创建此程序后现在执行您的示例



3.Test theTest代码示例



让我知道你如何查看这些区块



问候

Smart003
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


这篇关于如何获取序列中的下一个值?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆