简体   繁体   中英

Does Perl DBI Support Oracle Subquery Factoring?

I have searched online for several days and cannot find an answer.

Does Perl DBI support Oracle Subquery Factoring (ie WITH-clause)?

As an example, the simple Perl DBI application further below fails with the error:

DBD::Oracle::st fetchrow_array failed: ERROR no statement executing (perhaps you need to call execute first)

Simple Perl DBI Application:

#!/bin/perl

use DBI;

my $sql = <<END_SQL;
WITH w AS
(
    SELECT wafer_seq
    FROM wafer
    WHERE load_time > sysdate - 1
)
SELECT v.*
FROM vwafer v, w
WHERE v.wafer_seq = w.wafer_seq
ORDER BY v.wafer_seq
END_SQL

my $dbh = DBI->connect('DBI:Oracle:<schema_id>', '<username>', '<password>');

my $sth = $dbh->prepare($sql) || die "ERROR PREP";

$sth->execute() || die "ERROR EXEC";

while (my @row = $sth->fetchrow_array())
{
    print "@row\n";
}

$sth->finish();

$dbh->disconnect();

exit 0;

This same application will work if I simply change the SQL to:

SELECT v.*
FROM vwafer v, 
    (
        SELECT wafer_seq
        FROM wafer
        WHERE load_time > sysdate - 1
    ) w
WHERE v.wafer_seq = w.wafer_seq
ORDER BY v.wafer_seq

Finally, I confirmed that both SQLs mentioned above work when executed directly in a database visualizer application (eg DBVisualizer).

It appears my version of Perl (5.8.8), DBI (1.58), and/or DBD::Oracle (1.19) do not support Oracle Subquery Factoring.

I was able to successfully execute the same Perl application through updated Perl (5.12.1), DBI (1.613), and DBD::Oracle (1.24) versions.

Unfortunately, even after reading change histories for Perl, DBI, and DBD::Oracle, I do not know exactly which component introduced support of Oracle Subquery Factoring. My suspicion is the DBI Oracle driver (DBD::Oracle).

Perl DBI correctly processed 'WITH' clause. I just now check it and test your code According to error there is may by only one case You forget to call

 $sth->execute();

Double check please are it called, may be it was commented or something else. But your code work correct.

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