Home » Infrastructure » Unix » How to assign a unix variable to a Oracle package variable in Unix Shell Script
How to assign a unix variable to a Oracle package variable in Unix Shell Script [message #157060] Tue, 31 January 2006 02:34 Go to next message
csatish
Messages: 5
Registered: January 2006
Junior Member
Hi,

I am unable to assign a unix variable to a oracle package variable which is being invoked in a sql plus session in a Unix Shell Script

The Script is as follows

test.sh
<<
prd_id=1
sqlplus scott/tiger@db << EOF
begin
pack_test.g_prod_id := $prd_id
execute dump_test;
end;
>>

pack_test is a package and a variable g_prod_id in the package spec. dump_test is a procedure

I am unable to execute this shell as the error is
ORA-06550: line 2, column 24:
PLS-00181: unsupported preprocessor directive '$prd_id'

Could you please let me know how to resolve this

Re: How to assign a unix variable to a Oracle package variable in Unix Shell Script [message #157093 is a reply to message #157060] Tue, 31 January 2006 05:27 Go to previous messageGo to next message
hellcat
Messages: 84
Registered: January 2006
Location: Zug, Switzerland
Member
you could parameterise the script...

the *.sql file:

begin
pack_test.g_prod_id := &1 -- or '&1' if it's a character
execute dump_test;
end;


the *.sh file:
sqlplus scott/tiger@db @*.sql $prd_id


hope you got the principle...
Re: How to assign a unix variable to a Oracle package variable in Unix Shell Script [message #157176 is a reply to message #157093] Tue, 31 January 2006 14:06 Go to previous message
andrew again
Messages: 2577
Registered: March 2000
Senior Member
#!/bin/ksh
## CREATE OR REPLACE PROCEDURE p1 (i_parm IN NUMBER, o_parm OUT NUMBER)
## IS
## BEGIN
##    o_parm := 5 * i_parm;
## END;
## /
my_in_parm=5
RETVAL=`sqlplus -s scott/tiger@dev <<EOF
set serveroutput on
WHENEVER SQLERROR EXIT 1
declare
x number := $my_in_parm;
y number;
begin
p1(x, y);
dbms_output.put_line('o_parm from p1 is '||y);
end;
/
exit;
EOF`

echo $RETVAL
X=`echo $RETVAL | awk '{print $5}'`
echo $X
Previous Topic: Give me suggestion
Next Topic: Solaris 10 Hardening Doc for 9i
Goto Forum:
  


Current Time: Sat Apr 20 07:41:43 CDT 2024