Equivalent in Perl

Discussion in 'Perl Misc' started by pankaj_wolfhunter@yahoo.co.in, Mar 12, 2007.

  1. Guest

    Greetings,

    Whats the equivalent for the following code in perl:

    sqlplus -s orauser/orapass@oadb << eof > output_file.txt
    some oracle queries
    exit;
    eof;

    I did this using "system" command.
    We've been told to do this using DBI or some other method?

    I tried with DBI but the problem is I dont know how to redirect the
    oracle output to
    to a file (outout_file.txt) instead of console.

    Help would be appreciated.

    TIA
     
    , Mar 12, 2007
    #1
    1. Advertising

  2. Guest

    "" <> wrote:
    > Greetings,
    >
    > Whats the equivalent for the following code in perl:
    >
    > sqlplus -s orauser/orapass@oadb << eof > output_file.txt
    > some oracle queries
    > exit;
    > eof;
    >
    > I did this using "system" command.


    That *is* the equivalent in Perl.

    > We've been told to do this using DBI or some other method?


    Was that a statement or a question? Why were you told this?
    If you were told this for a reason, that reason matters.

    > I tried with DBI but the problem is I dont know how to redirect the
    > oracle output to
    > to a file (outout_file.txt) instead of console.


    You use DBI when you want the data to come into Perl (from where you can
    wrangle and format and print to your heart's content--just like you can
    with any other data in Perl). If you just want it sent to a file exactly
    the way sqlplus does it, then just use system and sqlplus.

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Mar 12, 2007
    #2
    1. Advertising

  3. Guest

    On Mar 12, 8:14 pm, wrote:
    > "" <> wrote:
    > > Greetings,

    >
    > > Whats the equivalent for the following code in perl:

    >
    > > sqlplus -s orauser/orapass@oadb << eof > output_file.txt
    > > some oracle queries
    > > exit;
    > > eof;

    >
    > > I did this using "system" command.

    >
    > That *is* the equivalent in Perl.
    >
    > > We've been told to do this using DBI or some other method?

    >
    > Was that a statement or a question? Why were you told this?
    > If you were told this for a reason, that reason matters.
    >
    > > I tried with DBI but the problem is I dont know how to redirect the
    > > oracle output to
    > > to a file (outout_file.txt) instead of console.

    >
    > You use DBI when you want the data to come into Perl (from where you can
    > wrangle and format and print to your heart's content--just like you can
    > with any other data in Perl). If you just want it sent to a file exactly
    > the way sqlplus does it, then just use system and sqlplus.
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > Usenet Newsgroup Service $9.95/Month 30GB


    Thanks Xho.
    > Was that a statement or a question


    That was a statement.

    Still if we need to convert the above code using DBI, how'll that be.
    Actually I tried myself but couldnt get through.
     
    , Mar 12, 2007
    #3
  4. Ted Zlatanov Guest

    On 12 Mar 2007 02:42:50 -0700 "" <> wrote:

    pwci> Whats the equivalent for the following code in perl:

    pwci> sqlplus -s orauser/orapass@oadb << eof > output_file.txt
    pwci> some oracle queries
    pwci> exit;
    pwci> eof;

    pwci> I did this using "system" command.
    pwci> We've been told to do this using DBI or some other method?

    pwci> I tried with DBI but the problem is I dont know how to redirect
    pwci> the oracle output to to a file (outout_file.txt) instead of
    pwci> console.

    You are confusing DBI with something else. DBI lets you make SQL
    queries inside Perl, `sqlplus' is never involved. You need to rewrite
    your queries to do the right thing inside Perl, essentially. Either
    learn DBI programming from one of the many online tutorials, or hire
    someone who understands the topic.

    Ted
     
    Ted Zlatanov, Mar 12, 2007
    #4
  5. Guest

    "" <> wrote:
    > >
    > > > sqlplus -s orauser/orapass@oadb << eof > output_file.txt
    > > > some oracle queries
    > > > exit;
    > > > eof;

    > >

    >
    > Still if we need to convert the above code using DBI, how'll that be.
    > Actually I tried myself but couldnt get through.


    I would start by reading the DBI docs, or maybe a book about using DBI.
    Surely you don't expect us to read the DBI docs to you, or just retype the
    docs into usenet, right?

    What did you try and what problems did you encounter?

    Did you establish a connection? If so, did you prepare and execute a
    query? If so, did you get the results? If so, do you know how to use join
    and print? If so, then what is left to be done?

    Xho

    --
    -------------------- http://NewsReader.Com/ --------------------
    Usenet Newsgroup Service $9.95/Month 30GB
     
    , Mar 12, 2007
    #5
  6. Guest

    On Mar 12, 11:01 pm, wrote:
    > "" <> wrote:
    >
    > > > > sqlplus -s orauser/orapass@oadb << eof > output_file.txt
    > > > > some oracle queries
    > > > > exit;
    > > > > eof;

    >
    > > Still if we need to convert the above code using DBI, how'll that be.
    > > Actually I tried myself but couldnt get through.

    >
    > I would start by reading the DBI docs, or maybe a book about using DBI.
    > Surely you don't expect us to read the DBI docs to you, or just retype the
    > docs into usenet, right?
    >
    > What did you try and what problems did you encounter?
    >
    > Did you establish a connection? If so, did you prepare and execute a
    > query? If so, did you get the results? If so, do you know how to use join
    > and print? If so, then what is left to be done?
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > Usenet Newsgroup Service $9.95/Month 30GB


    Thanks for replying.
    As I told before also i did try it with DBI and all I couldnt do is
    how
    to redirect the output instead of console to a file.
    Neverming here's my code

    #!/usr/bin/perl -w

    use DBI;

    $dbh = DBI->connect("DBI:Oracle:eek:radb","username","password") || die
    "Database Connection not Made : $DBI::errstr\n";

    ### Prepare a SQL statement for execution
    $sth = $dbh->prepare( "SELECT SYSDATE FROM DUAL1" );

    ### Execute the statement in the database
    $sth->execute();
    $sth->finish();
    $dbh->disconnect();

    Now whatever is the output (error or actual output) goes to console.
    How to redirect it to file instead of console.

    I tried using STDERR but couldnt get it to work.

    What code to put exactly where in order to achieve this?

    TIA
     
    , Mar 13, 2007
    #6
  7. Guest

    On Mar 12, 11:01 pm, wrote:
    > "" <> wrote:
    >
    > > > > sqlplus -s orauser/orapass@oadb << eof > output_file.txt
    > > > > some oracle queries
    > > > > exit;
    > > > > eof;

    >
    > > Still if we need to convert the above code using DBI, how'll that be.
    > > Actually I tried myself but couldnt get through.

    >
    > I would start by reading the DBI docs, or maybe a book about using DBI.
    > Surely you don't expect us to read the DBI docs to you, or just retype the
    > docs into usenet, right?
    >
    > What did you try and what problems did you encounter?
    >
    > Did you establish a connection? If so, did you prepare and execute a
    > query? If so, did you get the results? If so, do you know how to use join
    > and print? If so, then what is left to be done?
    >
    > Xho
    >
    > --
    > --------------------http://NewsReader.Com/--------------------
    > Usenet Newsgroup Service $9.95/Month 30GB


    Thanks for replying.
    As I told before I tried this with DBI but just didnt know
    how to redirect the output to a file.

    here's the code I used:

    #!/usr/bin/perl -w

    use DBI;

    $dbh = DBI->connect("DBI:Oracle:ndmid","ssatyasa","ssatyasa") || die
    "Database Connection not Made : $DBI::errstr\n";

    ### Prepare a SQL statement for execution
    $sth = $dbh->prepare( "SELECT SYSDATE FROM DUAL1" );

    ### Execute the statement in the database
    $sth->execute( );
    $sth->finish();
    $dbh->disconnect();

    I tried redirecting using STDERR but just couldnt make it work.
    What to put and exactly where?

    Any help?

    TIA
     
    , Mar 13, 2007
    #7
  8. Guest

    On Mar 13, 2:32 pm, Ian Wilson <> wrote:
    > wrote:
    >
    > > here's the code I used:

    >
    > > #!/usr/bin/perl -w

    >
    > > use DBI;

    >
    > > $dbh = DBI->connect("DBI:Oracle:ndmid","ssatyasa","ssatyasa") || die
    > > "Database Connection not Made : $DBI::errstr\n";

    >
    > > ### Prepare a SQL statement for execution $sth = $dbh->prepare(
    > > "SELECT SYSDATE FROM DUAL1" );

    >
    > > ### Execute the statement in the database $sth->execute( );
    > > $sth->finish(); $dbh->disconnect();

    >
    > > I tried redirecting using STDERR but just couldnt make it work. What
    > > to put and exactly where?

    >
    > Since you are apparently unable to use Google, I did it for you. I typed
    > in "perl DBI example" and looked at the first item returned. I recommend
    > you get into the habit of using Google.
    >
    > http://www.saturn5.com/~jwb/dbi-examples.htmlhas this example
    >
    > ------------------------------------8<--------------------------------
    > use strict;
    > use DBI;
    >
    > my $dbh = DBI->connect( 'dbi:Oracle:eek:rcl',
    > 'jeffrey',
    > 'jeffspassword',
    > {
    > RaiseError => 1,
    > AutoCommit => 0
    > }
    > ) || die "Database connection not made:
    > $DBI::errstr";
    >
    > my $sql = qq{ SELECT id, name, title, phone FROM employees };
    > my $sth = $dbh->prepare( $sql );
    > $sth->execute();
    >
    > my( $id, $name, $title, $phone );
    > $sth->bind_columns( undef, \$id, \$name, \$title, \$phone );
    >
    > while( $sth->fetch() ) {
    > print "$name, $title, $phone\n";
    >
    > }
    >
    > $sth->finish();
    > $dbh->disconnect();
    > ------------------------------------8<--------------------------------
    >
    > I'm assuming you know how to use Perl to open a file for writing and how
    > to compose a perl "print" statement to write to a file. If not try using
    > the perl documentattion by typing these commands:
    > perldoc -f open
    > perldoc -f print
    >
    > With that knowledge you can adapt the above example to write the SQL
    > data to a file.- Hide quoted text -
    >
    > - Show quoted text -


    Thanks Ian and thanks all.
    Didnt know that I am asking something which is really bugging a lot of
    ppl here.
    Next time I gotta be a bit careful
    Thanks again.
     
    , Mar 13, 2007
    #8
  9. <> wrote:
    > On Mar 13, 2:32 pm, Ian Wilson <> wrote:
    >> wrote:


    >> > I tried redirecting using STDERR but just couldnt make it work. What
    >> > to put and exactly where?

    >>
    >> Since you are apparently unable to use Google, I did it for you. I typed
    >> in "perl DBI example" and looked at the first item returned. I recommend
    >> you get into the habit of using Google.



    > Didnt know that I am asking something which is really bugging a lot of
    > ppl here.



    You didn't know that you were treating a lot of people (not ppl)
    with disrespect when you asked your question without trying
    even a little bit to answer it yourself first?

    I don't see how that outcome could be surprising...


    > Next time I gotta be a bit careful



    Next time you simply have to respect the time of others.


    --
    Tad McClellan SGML consulting
    Perl programming
    Fort Worth, Texas
     
    Tad McClellan, Mar 14, 2007
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. DG
    Replies:
    2
    Views:
    4,653
    Jeff Schwab
    May 22, 2004
  2. Manasa
    Replies:
    1
    Views:
    740
    Skeleton Man
    Jun 4, 2004
  3. Mark
    Replies:
    2
    Views:
    1,133
  4. Vinay Gupta
    Replies:
    2
    Views:
    1,137
    Michael Schlenker
    Jul 27, 2004
  5. Page
    Replies:
    1
    Views:
    490
    Michael Borgwardt
    Sep 9, 2004
Loading...

Share This Page