Re: Shell script to catch PL/SQL return values



Hi send.vamsi@xxxxxxxxx,

I was able to assign a single return value from the SQL statement to
the shell variable as below, but what about multiple values...

.... how's something like this?

====================================8<------------------------------------

#!/bin/bash

OUTPUT=$(sqlplus -s '/ as sysdba' <<-EOF
set heading off feedback off serveroutput on trimout on pagesize 0

select instance_name from v\$instance;
select version from v\$instance;

declare
i number := 0;
begin
while i < 3 loop
dbms_output.put_line(i);
i := i+1;
end loop;
end;
/
EOF
)

INSTANCE=$(echo $OUTPUT | awk '{ print $1 }')
VERSION=$(echo $OUTPUT | awk '{ print $2 }')
ARG1=$(echo $OUTPUT | awk '{ print $3 }')
ARG2=$(echo $OUTPUT | awk '{ print $4 }')
ARG3=$(echo $OUTPUT | awk '{ print $5 }')

echo "Database: $INSTANCE"
echo "Version: $VERSION"
echo "Arg1: $ARG1"
echo "Arg2: $ARG2"
echo "Arg3: $ARG3"

====================================8<------------------------------------

Note the escaped dollar sign. The output then looks something like this:

Database: MYDB
Version: 10.2.0.1.0
Arg1: 0
Arg2: 1
Arg3: 2

Also note that you don't need a spool file...
--
cul8er

Paul
paul.foerster@xxxxxxx
.



Relevant Pages

  • Re: Shell script to catch PL/SQL return values
    ... echo "Database: $INSTANCE" ... echo "Arg1: $ARG1" ... echo "Arg2: $ARG2" ... echo "Arg3: $ARG3" ...
    (comp.databases.oracle.misc)
  • Re: Array of subroutines
    ... call array(arg1, arg2, arg3) ... The Metcalf/Reid/Cohen book shows an example of how to pass a subroutine ...
    (comp.lang.fortran)
  • Re: Array of subroutines
    ... subroutine array(index, arg1, arg2, arg3) ... I would consider gathering arguments arg1, arg2, arg3 into a derived ...
    (comp.lang.fortran)
  • Re: What are python closures realy like?
    ... def foobar(arg1, arg2, arg3): ... do something with arg1 and argument ... do something with arg1 and arg2 ...
    (comp.lang.python)