Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.misc -> Re: Oracle variable to unix script/environment
>
> How does one create a variable from a select statement and
pass it back to the
> shell script? In other words, I want to do something like
this from sqlplus:
>
> column aa new_value bb noprint;
> select sysdate aa from dual;
>
> The oracle variable &bb now contains the value of sysdate
but, how do I pass
> &bb either to a shell script or as an environment variable
outside of Oracle?
>
>
here is an example of some code (bourne/korn shell) that can
pass a variable from an sqlplus session to the unix
environment.
getinterval () {
getoraid
sqlplus -SILENT /NOLOG <<sqlplusdone
connect $oraid/$orapassword@$oraconnectstring
set feedback off
declare
interval integer;
begin
select failinterval into interval from ctms.jobdefaults where
procedurename='$1';
interval:=-20224-interval;
if (interval<-20999) then
interval:=-20999;
end if;
raise_application_error(interval,'return value');
end;
.
/
exit sql.sqlcode
sqlplusdone
export delayinterval=$?
}
please note that this only works with numeric variables and the
shell will truncate the return value to the lowest 8 bits
(value of 0 to 255) since it views this information as a return
code from the sqlplus program.
it is possible to get any kind of data out of oracle by using
PERL. here is a code snippet that executes a stored function in
an oracle database and returns the value to the unix
environment.
############### # # set up uses statements here #
# # body of code here #
or die "unable to connect: $DBI::errstr";
$db->{RaiseError} = 1;
$csr=$db->prepare(q{
begin :fileid := ctms.statustrack.getfileid(to_number(:iseqid)); end; });
--
This answer is courtesy of QuestionExchange.com
http://www.questionexchange.com/showUsenetGuest.jhtml?ans_id=6402&cus_id=USENET&qtn_id=4513
Received on Mon Oct 25 1999 - 20:51:29 CDT
![]() |
![]() |