How to access an Oracle database from Perl?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/11525722/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
How to access an Oracle database from Perl?
提问by Bill
I'm converting some shell scripts to perl. All the database access is done using sqlplus. With perl is that a better way to access an Oracle database or should I just stick to sqlplus.
I'm converting some shell scripts to perl. All the database access is done using sqlplus. With perl is that a better way to access an Oracle database or should I just stick to sqlplus.
回答by Quentin
DBIis the standard Perl database interface (unsurprisingly, it has an Oracle driver). DBIx::Classwraps it with a nice ORM interface.
DBIis the standard Perl database interface (unsurprisingly, it has an Oracle driver). DBIx::Classwraps it with a nice ORM interface.
SQL Plus appears to be a command line interface to Oracle. To use it from Perl you would have to construct your queries by mashing strings together (a great way to introduce SQL injection problems), shell out to the command line client, then parse the text output. That is madness. Use an interface that gives you Perl data structures to work with.
SQL Plus appears to be a command line interface to Oracle. To use it from Perl you would have to construct your queries by mashing strings together (a great way to introduce SQL injection problems), shell out to the command line client, then parse the text output. That is madness. Use an interface that gives you Perl data structures to work with.
回答by PinkElephantsOnParade
Here is a short example of usage of DBI:
Here is a short example of usage of DBI:
use DBI;
$user = 'donny';
$password = 'ppp';
$dbconnectstring = 'basetest';
$dbh = DBI->connect('dbi:Oracle:',$user.'@'.$password,$dbconnectstring);
Also, note you can access sqlplus - or any command line - within a perl script. Just use backticks:
Also, note you can access sqlplus - or any command line - within a perl script. Just use backticks:
`cd dasd`
For example. Not sure if you'd want to do this, but just an idea, since you said you're converting shell to perl.
For example. Not sure if you'd want to do this, but just an idea, since you said you're converting shell to perl.