While it is possible to do this: just do something like:

undef $/; # read files all in one go
open(SQL, $sql_file) || die "Could not open $sql_file";
$sql = <SQL>;
close(SQL);
$sth = $dbh->prepare($sql);
etc

I would suggest you consider enforcing the use of PL/SQL procedures and
functions instead. i.e. ban raw SQL.

Regards
Chris

----- Original Message ----- 
From: "Oracle Monk" <[EMAIL PROTECTED]>
To: <[EMAIL PROTECTED]>
Sent: Friday, February 27, 2004 7:27 AM
Subject: including sql files in a main perl script.


Hi all,

I want to know is it possible to include .sql files in a main perl script?

I don't want write sql statements inside a perl script, rather i want to
keep the sql files in a seperate folder and then use a perl script to read
those sql files, prepare them and then execute them as we can do in a shell
script (its easy in shell as we use the sqlplus @filename).

Actually im trying to prepare a delivery installation script for our
application for which we are currently using shell scripts. I know that the
sqlplus can be called from the perl script to do this but i wanted to use
pure perl, DBI and .sql files only so that the script could be run from any
machine (including windows) which does not have oracle client installed.

The reason for having seperate .sql files is that only the sql files need to
be changed if required and not the perl script (good for someone who does
not know perl). Its like having create table scripts in seperate folder say
tables, create index in seperate folder say indexes and so on, so that if a
new table needs to be added for delivery only a new sql file has to be kept
in the table folder.

Pardon me if this is a stupid question.

Regards

Oracle Monk

Reply via email to