Beefy Boxes and Bandwidth Generously Provided by pair Networks
Perl Monk, Perl Meditation
 
PerlMonks  

Re^2: Run SQL script which contains multiple line statements

by karthik.raju (Acolyte)
on Dec 22, 2016 at 09:04 UTC ( [id://1178339]=note: print w/replies, xml ) Need Help??


in reply to Re: Run SQL script which contains multiple line statements
in thread Run SQL script which contains multiple line statements

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.

Replies are listed 'Best First'.
Re^3: Run SQL script which contains multiple line statements
by Corion (Patriarch) on Dec 22, 2016 at 09:14 UTC

    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.

Re^3: Run SQL script which contains multiple line statements
by talexb (Chancellor) on Dec 22, 2016 at 14:25 UTC
      ... 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.

Re^3: Run SQL script which contains multiple line statements
by poj (Abbot) on Dec 22, 2016 at 15:56 UTC
    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://1178339]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2024-04-23 02:49 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found