Script to give plsql procedure output


 
Thread Tools Search this Thread
Top Forums Shell Programming and Scripting Script to give plsql procedure output
# 1  
Old 01-12-2012
Script to give plsql procedure output

Code:
##Execute the EDW_MEM_KEY_UPDATE procedure
ext_sta=`sqlplus -s ${Connstr} <<eof
set heading off;
set pagesize 0;
set feedback off;
set serveroutput on;
execute EDW_MEM_KEY_UPDATE ;
quit;
here`
vara="ORA-"
var=`echo $ext_sta | grep -c $vara `




Hi All,

above is a part of my unix script, where i want to execute the procedure EDW_MEM_KEY_UPDATE and show its output through unix.

The output of procedure is like
Code:

Executed Successfully -- policy_key= 1 and membeber_key=12
Executed Successfully -- policy_key= 2 and membeber_key=13
---------- 


Incase of any error, while executing the procedure, i want to display the error

Kindly help.Smilie


---------- Post updated at 12:44 AM ---------- Previous update was at 12:43 AM ----------
Code:
vara="ORA-"
var=`echo $ext_sta | grep -c $vara

I am doing this part to find any oracl related error and then to show error msg through unix, that was an issue.

Moderator's Comments:
Mod Comment Video tutorial on how to use code tags in The UNIX and Linux Forums.

Last edited by radoulov; 01-12-2012 at 05:26 AM..
# 2  
Old 01-12-2012
Code:
 
ext_sta=`sqlplus -s ${Connstr} <<eof
set heading off;
set pagesize 0;
set feedback off;
set serveroutput on;
execute EDW_MEM_KEY_UPDATE ;
quit;
eof`

This User Gave Thanks to itkamaraj For This Post:
# 3  
Old 01-12-2012
Hi I am still not getting the required output.

I got below mentioned output.

Code:
SQL*Plus: Release 11.2.0.1.0 Production Copyright (c) 1982, 2009, Oracle. All rights reserved. Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements. 
Usage
[sqlplus usage message snipped]

---------- How to avoid this ? and i still dint got the output of the procedure Smilie
This is wat i tried now

Code:
 
ext_sta=`sqlplus -s ${Connstr} <<eof
set heading off;
set pagesize 0;
set feedback off;
set serveroutput on;
execute EDW_MEM_KEY_UPDATE ;
quit;
eof`
echo ${ext_sta}


Last edited by radoulov; 01-12-2012 at 05:28 AM..
# 4  
Old 01-12-2012
The connect string should not be in a single variable.
Try setting user, password and tns alias in three different variables and then use them like this:

Code:
sqlplus -s "$user"/"$pass"@"tns_alias" ...

# 5  
Old 01-12-2012
Thanks for the quick response radoulov

Well i have already defined my Connstr a
Code:
Connstr="${ora_user}/${dbpwd}@${ora_db}"

# 6  
Old 01-12-2012
I mean that you need:

Code:
ext_sta=`sqlplus -s "$ora_user"/"$dbpwd"@"$ora_db" <<eof
set heading off;
set pagesize 0;
set feedback off;
set serveroutput on;
execute EDW_MEM_KEY_UPDATE ;
quit;
eof`
echo "$ext_sta"

and not:

Code:
ext_sta=`sqlplus -s ${Connstr} <<eof
set heading off;
set pagesize 0;
set feedback off;
set serveroutput on;
execute EDW_MEM_KEY_UPDATE ;
quit;
eof`
echo ${ext_sta}

# 7  
Old 01-12-2012
Sir , i still dint got the required output, but the same previous output.

Code:
Executing the EDW_MEM_KEY_UPDATE procedure
SQL*Plus: Release 11.2.0.1.0 Production Copyright (c) 1982, 2009, Oracle. All rights reserved. Use SQL*Plus to execute SQL, PL/SQL and SQL*Plus statements. Usage 1: sqlplus -H | -V -H Displays the SQL*Plus version and the usage help. -V Displays the SQL*Plus version. Usage 2: sqlplus [ [<option>] [{logon | /nolog}] [<start>] ] <option> is: [-C <version>] [-L] [-M "<options>"] [-R <level>] [-S] -C <version> Sets the compatibility of affected commands to the version specified by <version>. The version has the form "x.y[.z]". For example, -C 10.2.0 -L Attempts to log on just once, instead of reprompting on error. -M "<options>" Sets automatic HTML markup of output. The options have the form: HTML [ON|OFF] [HEAD text] [BODY text] [TABLE text] [ENTMAP {ON|OFF}] [SPOOL {ON|OFF}] [PRE[FORMAT] {ON|OFF}] -R <level> Sets restricted mode to disable SQL*Plus commands that interact with the file system. The level can be 1, 2 or 3. The most restrictive is -R 3 which disables all user commands interacting with the file system. -S Sets silent mode which suppresses the display of the SQL*Plus banner, prompts, and echoing of commands. <logon> is: {<username>[/<password>][@<connect_identifier>] | / } [AS {SYSDBA | SYSOPER | SYSASM}] [EDITION=value] Specifies the database account username, password and connect identifier for the database connection. Without a connect identifier, SQL*Plus connects to the default database. The AS SYSDBA, AS SYSOPER and AS SYSASM options are database administration privileges. <connect_identifier> can be in the form of Net Service Name or Easy Connect. @[<net_service_name> | [//]Host[:Port]/<service_name>] <net_service_name> is a simple name for a service that resolves to a connect descriptor. Example: Connect to database using Net Service Name and the database net service name is ORCL. sqlplus myusername/mypassword@ORCL Host specifies the host name or IP address of the database server computer. Port specifies the listening port on the database server. <service_name> specifies the service name of the database you want to access. Example: Connect to database using Easy Connect and the Service name is ORCL. sqlplus myusername/mypassword@Host/ORCL The /NOLOG option starts SQL*Plus without connecting to a database. The EDITION specifies the value for Session Edition. <start> is: @<URL>|<filename>[.<ext>] [<parameter> ...] Runs the specified SQL*Plus script from a web server (URL) or the local file system (filename.ext) with specified parameters that will be assigned to substitution variables in the script. When SQL*Plus starts, and after CONNECT commands, the site profile (e.g. $ORACLE_HOME/sqlplus/admin/glogin.sql) and the user profile (e.g. login.sql in the working directory) are run. The files may contain SQL*Plus commands. Refer to the SQL*Plus User's Guide and Reference for more information.

Login or Register to Ask a Question

Previous Thread | Next Thread

10 More Discussions You Might Find Interesting

1. Homework & Coursework Questions

How to Dynamically Pass Parameter to plsql Function & Capture its Output Value in a Shell Variable?

Use and complete the template provided. The entire template must be completed. If you don't, your post may be deleted! 1. The problem statement, all variables and given/known data: 2. Relevant commands, code, scripts, algorithms: #! /bin/ksh v="ORG_ID" ... (2 Replies)
Discussion started by: sujitdas2104
2 Replies

2. Shell Programming and Scripting

Creating IN list in PLSQL script dynamically by using shell script

Hi all, I have a PLSQL script which has a IN list where it takes some ids as input. For example SELECT * FROM EMPLOYEE WHERE EMPLOYEE_ID IN (comma separated list ) I want to run this quest inside a shell script but I would like to prepare the IN list dynamically where the employee ids... (1 Reply)
Discussion started by: LoneRanger
1 Replies

3. Shell Programming and Scripting

How to give full access to output files created by .sh script run via crontab?

Hi Expert, I have a .sh script in my home/new_dir/script.sh This script creates number of output files at home/new_dir/email, home/new_dir/logs dir. I am running this script using crontab (owner root). Now this output files are getting created with rw-r----- 1 root root So if i... (2 Replies)
Discussion started by: Jeet1982
2 Replies

4. Shell Programming and Scripting

calling a plsql procedure through shell script

I have a plsql procedure inside a package which is having one IN parameter .I want to call that procedure through a shell script and that IN parameter is a column of a table in the database. So my requirement is that i need to loop all the entries of that IN parameter from the table through shell... (4 Replies)
Discussion started by: rspnf
4 Replies

5. Shell Programming and Scripting

Capturing output of procedure in variable in shell script

Hi guys I am calling one DB2 stored proc through unix. It is giving me below output. I want to capture the value 150 in one UNIX variable in shell script. Please let me know how I can achieve this. Thanks in advance Value of output parameters -------------------------- Parameter Name :... (5 Replies)
Discussion started by: vnimavat
5 Replies

6. Shell Programming and Scripting

How to give a variable output name in a shell script inside a for loop

Hi all I run my program prog.c in the following way : $ ./prog 1 > output.txt where 1 is a user defined initial value used by the program. But now I want to run it for many a thousand initial values, 1-1000, and store all the outputs in different files. Like $ ./prog 1... (1 Reply)
Discussion started by: alice06
1 Replies

7. Shell Programming and Scripting

Execute stored procedure through script in sybase database and store the output in a .csv file

Hi, I have a sybase stored procedure which takes two input parameters (start_date and end_date) and when it get executed, it gives few records as an output. I want to write a unix script (ksh) which login to the sybase database, then execute this stored procedure (takes the input parameter as... (8 Replies)
Discussion started by: amit.mathur08
8 Replies

8. Shell Programming and Scripting

How to Pass the Output Values from the PL/SQL Procedure to Shell Script?

hi, Could anyone tell me how to pass the output values of the PL/SQL procedure to Shell script and how to store that values in a shell script variable... Thanks in advance... (5 Replies)
Discussion started by: funonnet
5 Replies

9. Shell Programming and Scripting

Call and redirect output of Oracle stored procedure from unix script

Hi, Can you assist me in how to redirect the output of oracle stored procedure from unix script? Something similar to what i did for sybase isql -U$MYDBLOG -D$MYDBNAME -S$MYDBSVR -P$MYDBPWD -o$MYFILE<< %% proc_my_test 8 go %% Thanks in advance - jak (0 Replies)
Discussion started by: jakSun8
0 Replies

10. UNIX for Dummies Questions & Answers

Save TCL Procedure Output

Hello Friend, In TCL i wrote a procedure as power, accepting two arguments and it was saved as a file named TCLProc.tcl. Now from unix, using shell script i want to run this procedure power,the output of this procedure should be saved in a text file.How can i do this.Please help me as early... (1 Reply)
Discussion started by: gjsaravanan
1 Replies
Login or Register to Ask a Question