I managed to get this work by placing the set of SQL commands in a string and then executing it using a system()
function:
my $result = 'sqlplus / as sysdba <<EOF;
create pfile=\'/tmp/pfile.ora\' from spfile;
exit;
EOF
';
system($result);
The first line tells it to execute the following here-doc in sqlplus / as sysdba
. The backslashes escape the single quotes in the pfile directory. Also, since only oracle
can run sqlplus
, it is already presumed that they are running the script as oracle
, negating the need to su
into it.