[英]how to connect to sqlplus using perl script
In unix the normal procedure that we use to connect to sqlplus is like this 在Unix中,我们用于连接到sqlplus的正常过程如下
sqlplus ${user}/${password}@${server} my_file.sql >> $Logfile 2>&1
where im appending all the info in the above command to the log file $Logfile
我将上述命令中的所有信息附加到日志文件
$Logfile
Now in perl i know how to connect to sqlplus and execute a sql script i used something like 现在在perl中,我知道如何连接到sqlplus并执行一个sql脚本,我使用了类似的方法
system("sqlplus -L ${user}/${password}@${server} my_file.sql")
but using system
we cannot send an info to a log file it will only give the return status i want to track the info of the executed command like we do in unix Is there a way to do this. 但是使用
system
我们不能将信息发送到日志文件,它只会给出返回状态,我想像在unix中那样跟踪已执行命令的信息。有没有办法做到这一点。 Please help Thanks 请帮忙谢谢
It is far better to access the database using DBI
and DBD::Oracle
rather than shelling out to run the interactive tool SQL*Plus . 使用
DBI
和DBD::Oracle
访问数据库要好得多,而不是花钱运行交互式工具SQL * Plus 。
But if you insist on creating a separate process to manipulate your database, then an identical command passed to system
will achieve the same results. 但是,如果您坚持要创建一个单独的过程来操作数据库,那么传递给
system
的相同命令将获得相同的结果。
I have assumed that you want the at sign @
in there literally? 我假设您确实要在其中
@
符号? Like this 像这样
system("sqlplus -L ${user}/${password}\@${server} my_file.sql >> $Logfile 2>&1")
Or you could use backticks: 或者您可以使用反引号:
open my ($log_fh), '>', $Logfile;
print $log_fh `sqlplus -L ${user}/${password}\@${server} my_file.sql`;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.