![]() |
|
|
|
|
|||||||
| Forums | Portal | Register | Forum Rules | FAQ | Contribute | Members List | Arcade | Search | Today's Posts | Mark Forums Read |
| Shell Programming and Scripting Post questions about KSH, CSH, SH, BASH, PERL, PHP, SED, AWK and OTHER shell scripts here. |
|
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Using .NET Stored Procedures in Oracle | iBot | Oracle Updates (RSS) | 0 | 04-06-2008 02:10 AM |
| sql query results in unix shell script | skyineyes | UNIX for Dummies Questions & Answers | 1 | 06-20-2007 07:56 AM |
| Shell arrays in oracle stored procedure | superprogrammer | Shell Programming and Scripting | 6 | 06-09-2005 03:36 PM |
| Environmental Variables - where stored ? | DGoubine | UNIX for Advanced & Expert Users | 5 | 03-22-2005 12:10 PM |
| Oracle stored procedure. | kamil | UNIX for Advanced & Expert Users | 2 | 11-05-2003 09:39 AM |
|
|
Submit Tools | LinkBack | Thread Tools | Display Modes |
|
|||
|
Oracle Query results to be stored in variables
Hi
I would like to know if there is a way to just have one ORACLE connection established, using which we can execute different queries and store the results under different variables. For e.g the following uses to two silent ORACLE connection to store the result under two different variables. Instead can we just be able to modify the code to use the same connection against multiple queries? #!/bin/bash Query1=`sqlplus -s user/pwd@host<<eof set serveroutput on; set feedback off; set linesize 1000; select name from success; --Just for e.g. EXIT; eof` ....Operation on $Query1 Query2=`sqlplus -s user/pwd@host<<eof set serveroutput on; set feedback off; set linesize 1000; select name from failure; --Just for e.g. EXIT; eof` ....Operation on $Query2 The reason for asking is that the same code is required to be repeated multiple times. Also, can you pls explain how to read the results stored in the variable line by line. For e.g. if Query1 results are: int1 int4 int5 I would like to be able to get int1 value first, get the second one int4 and get the last one int5. Just would like to know how to perform a loop and read each line. Thanks for your help. Ashok |
| Forum Sponsor | ||
|
|
|
|||
|
Print the Query output in Shell Script.
RETVAL=`sqlplus -s user/pwd@host <<EOF
SET SERVEROUTPUT ON SIZE 100000 Declare OUT_MSG VARCHAR2(200); Begin select name into OUT_MSG from table_success; dbms_output.put_line ('KeepThis '||nvl(OUT_MSG,'')); End; / SET SERVEROUTPUT OFF EXIT; EOF` X=`echo $RETVAL | grep KeepThis | awk '{print $2}'` Y=`echo $RETVAL | grep KeepThis | awk '{print $3}'` Z=`echo $RETVAL | grep KeepThis | awk '{print $4}'` echo "The Query output is: " echo "Query OUT_MSG 1= $X " echo "Query OUT_MSG 2= $Y " echo "Query OUT_MSG 3= $Z " If you have more outputs from query, print those results in $5, $6,...... |
|||
| Google The UNIX and Linux Forums |
| Thread Tools | |
| Display Modes | |
|
|