开发者

sqlplus and Ruby

Anybody knows how to use sqlplus in ruby? I need to do something like this: system("sqlplus username开发者_C百科/pwd@database filename.sql"

Thx /Niklas


To get sqlplus to read its input from a file you need to prefix the filename with an @ symbol. So the following would work:

system("sqlplus", "username/pwd@database", "@filename.sql")

system can either be called with a single argument (your complete command) or multiple arguments (with the arguments to your command separated out as in the above example). The documentation for Kernel#exec describes the difference (system behaves in the same way):

If exec is given a single argument, that argument is taken as a line that is subject to shell expansion before being executed. If multiple arguments are given, the second and subsequent arguments are passed as parameters to command with no shell expansion. If the first argument is a two-element array, the first element is the command to be executed, and the second argument is used as the argv[0] value, which may show up in process listings.

Note: If you want sqlplus to exit and return to your ruby program after running the SQL then make sure you include a quit statement at the end of your SQL file.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜