oracle中的顺序问题
首先,我在 perl 脚本中的 oracle 中创建了一个序列。我得到一个错误,说明序列已创建错误。有没有办法重置序列(创建或替换不起作用)
create or replace sequence test_seq start with 1900 increment by 1 nomaxvalue
sprintf("INSERT INTO Custodian_New (Loginid,Type, Id, User, TimeCreated, RcNumber) values ('%s',1, %d, '%s', %d, '%s')", seq_name.nextVal,$dd, $Name, time(), $rc_num);
perl 脚本中的上述语句打印:“test_seqnextVal”顺序。 所以出现错误
DBD::Oracle::db do failed: ORA-01722: invalid number (DBD ERROR: error possibly near <*>seq_name )occurs.
请建议我问题是什么?谢谢。
Firstly i have created a sequence in oracle in perl script.I get a error statiing sequence already created error.Is there any means to reset the sequence(Create or replace doesnt work)
create or replace sequence test_seq start with 1900 increment by 1 nomaxvalue
sprintf("INSERT INTO Custodian_New (Loginid,Type, Id, User, TimeCreated, RcNumber) values ('%s',1, %d, '%s', %d, '%s')", seq_name.nextVal,$dd, $Name, time(), $rc_num);
The above statement in perl script prints:'test_seqnextVal' for the sequence.
So an error
DBD::Oracle::db do failed: ORA-01722: invalid number (DBD ERROR: error possibly near <*>seq_name )occurs.
Please suggest me on what is the problem?Thanks.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
对于 ORA-01722,您的
sprintf
在%s
周围有单引号,因此它将尝试插入字符串"seq_name.nextVal"
进入数字字段而不是序列中的值;该字符串无法转换为数字,因此会出现错误。您可以删除单引号:或者直接嵌入序列,因为动态构建它似乎没有任何意义:
或者更好的是,使用绑定变量并将其设置为
$dd
等。还使用sysdate
而不是传入time()
,但不知道这是否真的有什么区别。For the ORA-01722, your
sprintf
is has single quotes around the%s
, so it will try to insert the string"seq_name.nextVal"
into the number field instead of a value from the sequence; that string can't be converted to a number, hence the error. You can remove the single quotes:Or just embed the sequence directly as there doesn't seem to be any point building it dynamically:
Or even better, use bind variables and set those to
$dd
etc. I'd also usesysdate
instead of passing intime()
, but don't know if that really makes any difference.对于序列重置,请参阅如何重置序列在 Oracle 中?
For the sequence reset, please see How do I reset a sequence in Oracle?