Problems in execution of sqlscript in unix


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Problems in execution of sqlscript in unix
# 1  
Old 12-13-2011
Problems in execution of sqlscript in unix

I am new to unix and trying to execute sql script from unix. I have function already in database and trying to execute it from Cygwin unix and getting stuck. Can someone guide me where I wrote the shell script wrong

Code:
sqlplus -s scott/tiger 

declare
a number:=3;
b number:=4;
c number;
d number;
begin
d := fn_multi_returns(a,b,c);
commit;
dbms_output.put_line(d);
end;

exit

# 2  
Old 12-13-2011
Quote:
Originally Posted by pyerragudi
I am new to unix and trying to execute sql script from unix. I have function already in database and trying to execute it from Cygwin unix and getting stuck. Can someone guide me where I wrote the shell script wrong

Code:
sqlplus -s scott/tiger 
 
declare
a number:=3;
b number:=4;
c number;
d number;
begin
d := fn_multi_returns(a,b,c);
commit;
dbms_output.put_line(d);
end;
exit

Two things:

(1) you forgot the forward-slash ("/") character immediately after the end of the PL/SQL block. Oracle stores the contents of a PL/SQL block in a buffer file in your client machine. The forward-slash character is a signal to Oracle to execute the buffer contents.

(2) you did not specify the here-document. That is required by your Unix/Linux shell to capture a multi-line string that is supposed to be fed to the sqlplus command.

Note carefully the code in red color below:

Code:
$
$
$ cat -n test_orcl_block.sh
  1  #!/usr/bin/bash
  2  sqlplus -s scott/tiger@your_db << EOF
  3  set time off timing off
  4  declare
  5    a number       := 3;
  6    b varchar2(20) := 'Hello, World!';
  7    c date;
  8    d number;
  9  begin
 10    c := TRUNC (SYSDATE, 'yyyy');
 11    d := -123.456789;
 12    dbms_output.put_line ('a = '|| a);
 13    dbms_output.put_line ('b = '|| b);
 14    dbms_output.put_line ('c = '|| c);
 15    dbms_output.put_line ('d = '|| d);
 16  end;
 17  /
 18  exit
 19  EOF
$
$
$ ./test_orcl_block.sh
a = 3
b = Hello, World!
c = 01-JAN-11
d = -123.456789
 
PL/SQL procedure successfully completed.
 
$
$
$

tyler_durden

Last edited by durden_tyler; 12-13-2011 at 04:59 PM..
# 3  
Old 12-13-2011
I modified my code as follows. It gives me following error:
SP2-0735: unknown SET option beginning "severoutpu..."

How do specify set serveroutput on, please advise

Code:

sqlplus -s scott/tiger << EOF



set severoutput on;
declare
a number:=3;
b number:=4;
c number;
d number;
begin
d := fn_multi_returns(a,b,c);
commit;
dbms_output.put_line(d);
end;
/
exit

EOF

---------- Post updated at 01:19 PM ---------- Previous update was at 01:12 PM ----------

I got it, it was my bad. I coded as "Set severoutput on" instead of "Set serveroutput on"

Code:
sqlplus -s scott/tiger << EOF 


set serveroutput on
declare
a number:=3;
b number:=4;
c number;
d number;
begin
d := fn_multi_returns(a,b,c);
commit;
dbms_output.put_line(d);
end;
/
exit

EOF

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Shell Programming and Scripting

Execution problems to call the DB table through UNIX

Hi All, I am beginner to the Unix scripting, i am writing a script to call the DB through Unix script. I have to read the files from the given path and in each file the first column i have to pick up and delete the row in the table based on that column. #!/bin/sh set -x # Check to see if... (8 Replies)
Discussion started by: spidy
8 Replies

2. UNIX for Beginners Questions & Answers

Execution problems

How to find a word in a directory which contains many files? i just want to count how many such words are present in all the files? This is the code which i tried for a single file echo "Enter the file name:" read file echo "Enter the word to search:" read word if then echo "The count... (4 Replies)
Discussion started by: Meeran Rizvi
4 Replies

3. HP-UX

Execution problems with swreg

HP UX 10.20 I have a directory "/var/spool/sw" which is supposed to be a "Depot" directory. Turns out it is not and when using the swreg command "swreg -l /var/spool/sw" I get errors in part ERROR for option "-l /var/spool/sw" keyword or it's value may be incorrect or the keyword does not apply... (3 Replies)
Discussion started by: Randydog
3 Replies

4. UNIX for Dummies Questions & Answers

Execution Problems with Cron

Good evening, ive got this cron to be run: if i run this manually it doesnt work,it takes me to the prompt again /export/app/CO/opge/scr/Informe_parametros_colombia.ksh >/dev/null 2>&1 here is the code fragment: coopge@coopge: opge PRODUCCION>more... (1 Reply)
Discussion started by: alexcol
1 Replies

5. UNIX for Dummies Questions & Answers

Execution Problems with UNIX.

Hi Team, I created one file like tst.pl, it contains #!/usr/bin/perl use Spreadsheet::ParseExcel; During execution it's showing error like use: command not found. Pleast let me suggest how to use this perl menthods in Unix. Thanks in Advance, Reards, Harris (5 Replies)
Discussion started by: harris
5 Replies

6. Shell Programming and Scripting

Execution Problems with if statements

Hi all, I habe a file called test.log, which contain following data : 0.0 0.1 0.1 0.1 0.1 0.2 0.3 0.3 0.4 0.4 0.6 8.7 8.8 17.2 I want to show the data which gater than 9.0 But my script not working. (4 Replies)
Discussion started by: mnmonu
4 Replies

7. Shell Programming and Scripting

Execution Problems

this my source file ************* fixed *************** Begin equipmentId : d9 processor : fox number : bhhhhhh Variable # 1: Id : 100 Type : 9 nType : s gType : 5f mType : 4 LField : England DataField : london Length ... (6 Replies)
Discussion started by: teefa
6 Replies

8. Shell Programming and Scripting

Execution Problems!!

i have been working on this for a about 12 hours today say's end of file un expected any idea's using the bourne shell and its driving me nuts worked fine in bash but prof says make it work in bourne and good luck worth 13% any help would be awesome #!/bin/sh trap "rm mnt2/source/tmp/* 2>... (1 Reply)
Discussion started by: mrhiab
1 Replies

9. Programming

execution problems with cron

how to store a date into file? and how we can access date from the file? ---------- Post updated at 06:09 AM ---------- Previous update was at 06:08 AM ---------- how we can store date in file? (1 Reply)
Discussion started by: causalmodi777
1 Replies

10. Shell Programming and Scripting

Execution problems with Find

the below cmd is not wrking in perl script find . -name "*e*" -exec wc -l {} \; its show the following error Can't modify system in scalar assignment at prjt.pl line 4, near ");" Execution of prjt.pl aborted due to compilation errors. (11 Replies)
Discussion started by: natraj005
11 Replies
Login or Register to Ask a Question