![]() |
|
|
google unix.com
|
|||||||
| Forums | Register | Forum Rules | Links | Albums | FAQ | Members List | Calendar | 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 and shell scripting languages here. |
More UNIX and Linux Forum Topics You Might Find Helpful
|
||||
| Thread | Thread Starter | Forum | Replies | Last Post |
| Passing shell variable to NAWK | wakhan | Shell Programming and Scripting | 1 | 04-23-2008 03:52 AM |
| split varibles and store fields into shell varible array | gratus | Shell Programming and Scripting | 3 | 10-11-2007 03:50 PM |
| passing awk variable to the shell script | bcheaib | Shell Programming and Scripting | 3 | 07-21-2004 11:00 AM |
| passing value to shell variable | trynew | Shell Programming and Scripting | 2 | 06-24-2002 03:13 PM |
| Using varible/varible substitution in Perl/sed Search & Replace | Breen | Shell Programming and Scripting | 3 | 05-08-2002 06:45 AM |
![]() |
|
|
LinkBack | Thread Tools | Search this Thread | Rate Thread | Display Modes |
|
|
|
|||||
|
Roopla, Thanks a lot. It worked for me with some fine tuning as below.
shell_var=`sqlplus -s scott/tiger << ! SET HEAD OFF; SELECT sysdate from dual; EXIT !` echo $shell_var But still I dont know how to pass multiple values from SQL to Shell script. Any help in this regard will definitely help all of us to enhance our knowledge. Once again Many thanks for your sincere help, Roopla. With Regards, Ganapati. ![]() |
|
|||||
|
Great help and many thanks for your guide 'Radoulov'.
Below code is working perfectly to pass multiple values from SQL to Shell script. printf "%s\n" "set pages 0 serverout on feed off" \ "select ENAME from emp where ENO=7021;" \ "select sysdate from dual;" \ "select min(sal) from emp;" \ "select max(sal) from emp;" \ "select avg(sal) from emp;" \ | sqlplus -s scott/tiger \ | { read var1; read var2; read var3; read var4; read var5; } echo "Employee Name is $var1" echo "Date is $var2" echo "Minimum of Salary is $var3" echo "Maximum of Salary is $var4" echo "Average of Salary is $var5" But still I've one more requirement....., What is the case for the same query where if I want assign more values to var1 ? printf "%s\n" "set pages 0 serverout on feed off" \ "select ENAME from emp;" \ "select sysdate from dual;" \ "select min(sal) from emp;" \ "select max(sal) from emp;" \ "select avg(sal) from emp;" \ | sqlplus -s scott/tiger \ | { read var1; read var2; read var3; read var4; read var5; } echo "Employee Name is $var1" echo "Date is $var2" echo "Minimum of Salary is $var3" echo "Maximum of Salary is $var4" echo "Average of Salary is $var5" Please help me last time. With Regards, Ganapati. ![]() |
|
|||||
|
You can try somthing like that (not tested) :
Code:
printf "%s\n" "set pages 0 serverout on feed off" \
"select sysdate from dual;" \
"select min(sal) from emp;" \
"select max(sal) from emp;" \
"select avg(sal) from emp;" \
"select ENAME from emp;" \
| sqlplus -s scott/tiger \
| { read read var2; read var3; read var4; read var5;
var1=""
while read emp
do
var1="$var1$emp "
done
}
echo "Employee Name is $var1"
echo "Date is $var2"
echo "Minimum of Salary is $var3"
echo "Maximum of Salary is $var4"
echo "Average of Salary is $var5"
Jean-Pierre. |
|
|||||
|
Do it all in the database, if possible.
If you _really_ have to mix sql/plsql and shell programming: - as array in bash: Code:
$ var1="($(printf "%s \n" "set pages 0 feed off" \
> "select ename from emp;"|sqlplus -s scott/tiger))"; \
> printf "The first element in \$var1 array is: %s, \
> the second: %s and so on ...\n" \
> "${var1[1]}" "${var1[2]}"
The first element in $var1 array is: ALLEN, the second: WARD and so on ...
Code:
$ var1="$(printf "%s \n" "set pages 0 feed off" \ > "select ename from emp;"|sqlplus -s scott/tiger)"; \ > echo "Quoted: $var1"; \ > echo "Unquoted:" $var1 Quoted: SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER Unquoted: SMITH ALLEN WARD JONES MARTIN BLAKE CLARK SCOTT KING TURNER ADAMS JAMES FORD MILLER if you use only one programming language. |
![]() |
| Bookmarks |
| Thread Tools | Search this Thread |
| Display Modes | Rate This Thread |
|
|