On 2003-08-19 13:45:48 +0100, Ronnie Cruickshank wrote:
> Does anyone know if DBI can cater for the running of a locally held 
> query? If I have a file called fred.sql in my local directory which 
> contains various SQL commands. I would execute this file as 
> @fred. In DBI I prepare this file - with the preceding Perl escape 
> character

Does this mean you call
    $dbh->prepare('@file')? 
or something like

    {
        local $/;
        open(F, '<file');
        my $f = <F>;
        close(F);
        $dbh->prepare($f);
    }
?

Neither would work.

> - and this goes fine.

That probably means that prepare doesn't really prepare the statement
but only saves it for execute.

> The DBI execute fails with - 
> DBD::Oracle::st execute failed: ORA-00900: 
> invalid SQL statement (DBD ERROR: OCI
> StmtExecute) at DBI_connect.org line 544.

prepare expects exactly one SQL statement. So '@file' cannot work
because that's not an SQL statement, and the second method doesn't work
because file probably contains several statements (and terminating
semicolons or slashes, which aren't part of the SQL statement either).

> Running the file as @fred works fine from 
> SQLPLUS - can this be done using DBI?

You could split the file into statements yourself (";\n" is probably a
good separator), Or you could wrap the whole thing in begin/end pair
(see DBD::Oracle and a PL/SQL book for details).

        hp

-- 
   _  | Peter J. Holzer      | Unser Universum w�re betr�blich
|_|_) | Sysadmin WSR / LUGA  | unbedeutend, h�tte es nicht jeder
| |   | [EMAIL PROTECTED]        | Generation neue Probleme bereit.
__/   | http://www.hjp.at/   |  -- Seneca, naturales quaestiones

Attachment: pgp00000.pgp
Description: PGP signature

Reply via email to