Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl: the Markov chain saw
 
PerlMonks  

Re: Run SQL script which contains multiple line statements

by talexb (Chancellor)
on Dec 21, 2016 at 14:50 UTC ( [id://1178300]=note: print w/replies, xml ) Need Help??


in reply to Run SQL script which contains multiple line statements

The DBI module has fairly complete documentation -- it should allow you to run SQL statements of any length. However, I don't see much effort (or any Perl) in this question.

What have you tried?

Alex / talexb / Toronto

Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

  • Comment on Re: Run SQL script which contains multiple line statements

Replies are listed 'Best First'.
Re^2: Run SQL script which contains multiple line statements
by karthik.raju (Acolyte) on Dec 22, 2016 at 09:04 UTC

    Hi, I've tried with this option

    system("D:\\oracle\\product\\11.2.0\\client_1\\BIN\\sqlplus.exe userna +me/password\@ServiceName");
    with this, we can able to open  sql > command prompt but now how we can pass the .sql file ?
    I've tried so many ways, like
    system("D:\\oracle\\product\\11.2.0\\client_1\\BIN\\sqlplus.exe creden +tials @C:\\Users\\namburuk\\Desktop\\CostSettlement_DBScripts\\MI_SCR +_0001_FS_sample.sql");
    but i'm getting few errors.

      Consider using DBI instead and running your SQL through Perl directly.

      All your other questions seem to relate more on how to operate the sqlplus.exe program. Can you please explain where Perl is necessary for the operation?

      Do you know how to run the sqlplus.exe program outside of Perl and get the results into a text file?

      Also, "a few errors" is not something we can provide specific help on. Please tell us what you did, the exact error message and what you expect to happen instead.

        ... but i'm getting few errors.

      Think about anyone, in any industry, trying to diagnose the root cause of a problem based on this comment. It's really an impossible task.

      By all means pass along *all* of the errors you've seen (OK, maybe just the first dozen), so that we can better diagnose what's going on.

      Alex / talexb / Toronto

      Thanks PJ. We owe you so much. Groklaw -- RIP -- 2003 to 2013.

      but i'm getting few errors.

      There is an error in the sql CREATE table statement in your OP, a trailing comma.
      Try something like this

      #!perl use strict; use warnings; # configuration my $sqlplus = 'sqlplus';#'D:/oracle/product/11.2.0/client_1/BIN/sqlplu +s.exe'; my $dir = 'C:/Users/namburuk/Desktop/CostSettlement_DBScripts/'; my $sqlfile = 'MI_SCR_0001_FS_sample.sql'; my $logon = 'user/password@ServiceName'; #open IN,'<',$dir.$sqlfile or die "$!"; my $sql = join '',<DATA> ; # use IN #close IN; # add exit to sql to return from command line open OUT,'>','~temp.sql' or die "$!"; print OUT $sql."\nexit;\n"; close OUT; # run sqlplus.exe in silent mode system($sqlplus,'-S',$logon,'@~temp.sql') == 0 or die "Couldn't launch $sqlplus: $!"; __DATA__ SELECT CURRENT_TIMESTAMP FROM DUAL; CREATE TABLE TRN_SAAA ( TRN_ST NUMBER (30) NOT NULL, TRN_SE NUMBER (30) NOT NULL, CHKD VARCHAR2 (1) DEFAULT 'N' NOT NULL ); INSERT INTO TRN_SAAA VALUES (1,1,'A'); INSERT INTO TRN_SAAA VALUES (2,1,'B'); INSERT INTO TRN_SAAA VALUES (3,1,'C'); SELECT * FROM TRN_SAAA;
      poj

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://1178300]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others admiring the Monastery: (7)
As of 2024-04-24 20:39 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found