Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.tools -> Re: How to return an value from Oracle to Unix in a shell scrtip.
Thanks for link, Conon. Let me know if you find (by chance) such sort of information among the Oracle Documentation. Probably the absence of it (or absence of mind) has led me to my previous message.
In article <fAVI5.9941$Bw1.6019_at_news.indigo.ie>,
"Conan" <conan@(no-spam)as-if.com> wrote:
> Hi
> the following where taken from oracle underground FAQ's
> (http://www.orafaq.org/faq2.htm)
>
> You can select a value from a database column directly into a Unix
shell
> variable. Look at the following shell script examples:
> #!/bin/sh
> VALUE=`sqlplus -silent "user/password_at_instance" <<END
> set pagesize 0 feedback off verify off heading off echo off
> select max(c1) from t1;
> exit;
> END`
> if [ -z "$VALUE" ]; then
> echo "No rows returned from database"
> exit 0
> else
> echo $VALUE
> fi
>
> Second example, using the SQL*Plus EXIT status code:
> #!/bin/ksh
> sqlplus -s >junk1 "usr/psw_at_instance" <<EOF
> column num_rows new_value num_rows format 9999
> select count(*) num_rows
> from table_name;
> exit num_rows
> EOF
> echo "Number of rows are: $?"
>
> Yet another example, only this time we will read multiple values from
> SQL*Plus into shell variables.
> sqlplus -s usr/psw_at_instance |& # Open a pipe to SQL*Plus
>
> print -p -- 'set feed off pause off pages 0 head off veri off line
500'
> print -p -- 'set term off time off'
> print -p -- "set sqlprompt ''"
>
> print -p -- "select sysdate from dual;"
> read -p SYSDATE
>
> print -p -- "select user from dual;"
> read -p USER
>
> print -p -- "select global_name from global_name;"
> read -p GLOBAL_NAME
>
> print -p -- exit
>
> echo SYSDATE: $SYSDATE
> echo USER: $USER
> echo GLOBAL_NAME: $GLOBAL_NAME
>
> HTH
>
> Conan
>
>
Sent via Deja.com http://www.deja.com/
Before you buy.
Received on Mon Oct 23 2000 - 09:20:47 CDT
![]() |
![]() |