473,387 Members | 1,464 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

sql output in UNIX shell

Hi,

I wrote a shell script where I connect to an oracle db(the connection works because I able to see the DBMS output) and I execute a procedure, but I am not able to get the return value from that procedure into one of the shell variables (i understand that procedure do not return values but i am using IN OUT and i want this out value to go into a variable declared in the shell). I made sure the procedure works in sqlplus and the OUT value is comming out. Below is the code.

LOGIN=user1
DB_PWD=`some passwork`

sqlplus -s <<!
${LOGIN}/${DB_PWD}
set head off;
set feed off;
set pages 0;
set verify off;
set feedback off;
set serveroutput on;

declare
ERRFLAG number := 0;
begin
procedure_return_error(ERRFLAG);
dbms_output.put_line(ERRFLAG); /* the value gets displayed here which means the sql connection works and the OUT value is comming through */
end ;
/
!
echo errorflag is ${ERRFLAG} /* the value does not come here and dont mind the ${ERRFLAG} it does not work with just $ERRFLAG either */
echo ${APPS_LOGIN}
exit 0

I also tried declaring a global variable like below:

LOGIN=user1
DB_PWD=`some passwork`
ERRFLAG = 0 // like this but this does not work either

sqlplus -s <<!
${LOGIN}/${DB_PWD}
set head off;
set feed off;
set pages 0;
set verify off;
set feedback off;
set serveroutput on;

begin
procedure_return_error(ERRFLAG);
dbms_output.put_line(ERRFLAG); // the value gets displayed here
end ;
/
!
echo errorflag is ${ERRFLAG} // the value does not come here
echo ${APPS_LOGIN}
exit 0

Please reply,
thank you.
Sep 20 '07 #1
3 10654
Expand|Select|Wrap|Line Numbers
  1. ERRFLAG="$(sqlplus -s <<!
  2. "$LOGIN"/"$DB_PWD"
  3. set pages 0 feed off serveroutput on
  4. begin
  5. procedure_return_error(ERRFLAG);
  6. dbms_output.put_line(ERRFLAG); // here you get the value
  7. end ;
  8. /
  9. !
  10. )"
  11.  
  12. echo "$ERRFLAG"
Sep 21 '07 #2
Thank you for your reply.
As I said earlier, I am using a procedure and not a function. So technically there is no return value that comes out of the sql block to go into the UNIX variable. The value falls into the parameter of the procedure. (ie. EPALS_GL_NREG_OUT_INT(PARAM); the value falls into the parameter PARAM). so i am looking for a way to assign the value of PARAM to a UNIX variable outside the sql block.
Sep 21 '07 #3
Thank you for your reply.
As I said earlier, I am using a procedure and not a function. So technically there is no return value that comes out of the sql block to go into the UNIX variable. The value falls into the parameter of the procedure. (ie. EPALS_GL_NREG_OUT_INT(PARAM); the value falls into the parameter PARAM). so i am looking for a way to assign the value of PARAM to a UNIX variable outside the sql block.

Yes,
I and as I said, you have to print it(modify your PL/SQL code or write a wrapper that prints it).
AFAIK there is no other way to pass it to the shell ....
Sep 22 '07 #4

Sign in to post your reply or Sign up for a free account.

Similar topics

4
by: rkoida | last post by:
Hello evryone I am a newbie to python. I have a makefile which i can compile in UNIX/LINUX, But i I am planning to write a python script which actually does what my MAKEFILE does. The make file...
2
by: Mohsin | last post by:
Hi all, I have a perl program which makes a user exit to the O/S (unix, solaris) to issue a O/S command. I know that the shell it invokes is NOT a korn shell, because I captured the shell info...
1
by: dk | last post by:
is there any way to invoke a unix shell script from .net? tia, dk
0
by: Aashif | last post by:
I want to call Unix Shell script which is available in other Server (Unix server) from windows application using C#. Currently the shell script runs the C program but the GUI is not good, So I want...
9
by: sohan | last post by:
Hi, I want to know how to connect and execute a db2 query from inside a UNIX shell script. Details: We have a unix shell script. We need to execute multiple db2 sql queries from this shell...
3
by: Deniz Dogan | last post by:
Hello. I was thinking about writing a UNIX shell program using Python. Has anyone got any experience on this? Is it even possible? I have programmed a simple shell in C before and I came to...
0
by: Purple Haze | last post by:
I have a stored procedure which returns a resultset. I am calling that stored procedure from UNIX shell script. I want the data in the result set to be exported to a .csv file. How can I do this...
21
by: Tom Gur | last post by:
Hi, It's seems that csh and tcsh acts a bit different when handling special characters in quotes. i.e: if i'll supply my program with the following arguments: -winpath "c:\\temp\\" tcsh will...
2
by: gagandutta01 | last post by:
Hi, Can anyone tell me how to execute a function declared in Oracle Package from Unix shell script? I created a shell script and after connecting to oracle database i am using exec @...
3
by: regnumber | last post by:
Hi. I am new to Unix. I need to write a Unix Shell Script to extract records from the table and write those extracted datas to a text file. DB using is DB2. Can anyone give me some sample...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.