leoberbert has asked for the wisdom of the Perl Monks concerning the following question:

Dear All, Could you help me how I can run queries using sqlplus operating system and store the fields in variables? I do not have the DBI and DBD installed on the machines! Does anyone have an alternative suggestion? Regards.

Replies are listed 'Best First'.
Re: Invoke sqlplus
by Anonymous Monk on Apr 09, 2014 at 02:43 UTC

      Ha, ha, you let my day start with a big laugh. I'm pretty sure that we have one of these "I'm-not-allowed-to-install-something-else-than-distribution-moduls" candidates here. In this case recommending a modules which isn't in core is a little bit sarcastic. :-)

      Have a good day
      McA

Re: Invoke sqlplus
by NetWallah (Canon) on Apr 09, 2014 at 06:11 UTC
    I have never heard of a "sqlplus operating system" - could you explain what that is ?

            What is the sound of Perl? Is it not the sound of a wall that people have stopped banging their heads against?
                  -Larry Wall, 1992

Re: Invoke sqlplus
by karlgoethebier (Abbot) on Apr 09, 2014 at 08:45 UTC
Re: Invoke sqlplus
by InfiniteSilence (Curate) on Apr 09, 2014 at 18:37 UTC
    You can write a quick SQL script that spools, execute it, and parse out its contents:
    spool "foobar.dat"; select count(*) from foo_table; exit;
    And then gather up the results somehow:
    perl -e '`sqlplus myuser/mypassword@server @foo.sql`; my $res = `cat +foo.dat`; if($res=~m/(\d+)/){print $1}'

    Celebrate Intellectual Diversity

      Spool does not require a semicolon. The semicolon ends the sql buffer to be sent via the CLI to the RDBMS. spool is a sqlplus command, hence no query buffer.

      Same comment holds for exit, except, there's no reason to bother with exit anyway. Just use a document. Here's an example from asktom:

      #!/bin/csh -f sqlplus scott/tiger <<EOF exec dbms_output.put_line( 'Hello' ); EOF