oracle中的顺序问题

发布于 2024-10-31 02:11:17 字数 564 浏览 8 评论 0原文

首先,我在 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

柒夜笙歌凉 2024-11-07 02:11:17

对于 ORA-01722,您的 sprintf%s 周围有单引号,因此它将尝试插入字符串 "seq_name.nextVal" 进入数字字段而不是序列中的值;该字符串无法转换为数字,因此会出现错误。您可以删除单引号:

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);

或者直接嵌入序列,因为动态构建它似乎没有任何意义:

sprintf("INSERT INTO Custodian_New (Loginid, Type, Id, User, TimeCreated, RcNumber) values (seq_name.nextVal, 1, %d, '%s', %d, '%s')", $dd, $Name, time(), $rc_num);

或者更好的是,使用绑定变量并将其设置为 $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:

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);

Or just embed the sequence directly as there doesn't seem to be any point building it dynamically:

sprintf("INSERT INTO Custodian_New (Loginid, Type, Id, User, TimeCreated, RcNumber) values (seq_name.nextVal, 1, %d, '%s', %d, '%s')", $dd, $Name, time(), $rc_num);

Or even better, use bind variables and set those to $dd etc. I'd also use sysdate instead of passing in time(), but don't know if that really makes any difference.

白云不回头 2024-11-07 02:11:17

对于序列重置,请参阅如何重置序列在 Oracle 中?

For the sequence reset, please see How do I reset a sequence in Oracle?

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文