简体   繁体   中英

DBD::Oracle and DBI error in perl

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

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.

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM