Script categories

Thursday, 24 October 2013

Unix variables set from SQL Plus

Passing a parameter out of a SQL script to a UNIX variable. Method 1 outputs a literal. Method 2 will output a variable entered by a user.

Method 1

Create a file, "oranum.sql", which looks as follows:

set heading off
connect user/pwd@oraserver
select 10 from dual;
exit


run it as follows:

ORANUM=`sqlplus -s /nolog @oranum.sql`
echo $ORANUM


Method 2

#!/bin/ksh
echo "Enter value"
read val2
sqlplus $ORA_USER/$ORA_PWD@$ORA_HOST  << EOF1
set serveroutput on
begin
  dbms_output.put_line('${val2}');
end;
/
exit
EOF1

1 comment:

  1. Thanks for providing this informative information you may also refer.
    http://www.s4techno.com/blog/2016/07/11/aix-paging-space-commands/

    ReplyDelete