Perl 中的 DBD::Oracle 和 DBI 错误

发布于 2024-11-06 14:32:53 字数 600 浏览 2 评论 0原文

我在 perl 和 DBI 模块方面遇到了一个奇怪的问题。有时我可以成功获取查询,但有时,当我添加一行与数据库访问或类似内容远程相关的代码时,我收到一条错误消息:

DBD::Oracle::st fetchrow_array 失败:错误没有语句执行(也许您需要先调用执行)[for Statement "select * from (...)"] 在 script.pl 第 18 行。

我使用 sqlplus 验证了我的select 命令在这里没有问题(当然,这就是为什么我说脚本有时可以工作!)

如果我在 perl 脚本中的 select 命令后面添加一个分号,我会收到另一个错误:

DBD::Oracle::db 准备失败:ORA-00911:无效字符(DBD 错误:'select * from (...)<*> 中的字符 970 处的 <*> 指示器附近可能存在错误;') [for 语句“select * from (...);”]位于 script.pl 第 13 行。

任何人都可以向我建议这里发生了什么吗?是因为sql命令太长(~900个字符)吗?

I am having a strange issue here with perl and DBI module. I can get the query successfully sometimes, but sometimes, when I add a line of code which is remotely related to database access or anything like that, I got an error saying:

DBD::Oracle::st fetchrow_array failed: ERROR no statement executing (perhaps you need to call execute first) [for Statement "select * from (...)"] at script.pl line 18.

I verified using sqlplus that my select command has no problem here (of course, that is why I said the script worked sometimes!)

If I added a semicolon after the select command in the perl script, I got another error saying:

DBD::Oracle::db prepare failed: ORA-00911: invalid character (DBD ERROR: error possibly near <*> indicator at char 970 in 'select * from (...)<*>;') [for Statement "select * from (...);"] at script.pl line 13.

Can anyone please suggest to me what is going on here? Is it because the sql command is too long (~900 chars)?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(2

尘曦 2024-11-13 14:32:53

该错误意味着您已经准备了一条语句但未执行它。如果您准备了一条语句,执行它并获取所有行,然后再次调用 fetch,您也可能会得到它,但我对此不太确定。在这种情况下,请勿在 SQL 末尾添加分号,因为这不是必需的。

有关执行属性,请参阅 https://metacpan.org/pod/DBI#Executed

That error means you've prepared a statement but not executed it. You may also get it if you prepared a statement, executed it and fetched all the rows then call fetch again but I'm less sure about that. Don't put semi-colons on the end of your SQL in this case as it is not required.

See https://metacpan.org/pod/DBI#Executed for th executed attribute.

淑女气质 2024-11-13 14:32:53

我遇到了同样的问题,我注意到在获取后我有一个 fetchrow_array,这就是问题所在。

while ($sth->fetch) {

  sth->fetchrow_array;
  $myvar = some logic here
  $myvar2 = some other logic here

}

我删除了 sth->fetchrow_array;现在一切正常:)

I had the same issue, and I notice that I had a fetchrow_array after a fetch, that was the problem.

while ($sth->fetch) {

  sth->fetchrow_array;
  $myvar = some logic here
  $myvar2 = some other logic here

}

I removed the sth->fetchrow_array; and now everything is working :)

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