I have a shell script that stores an array of values picked up as input from its parent script.
This array needs to be used within a block of PL/SQL code. I need to iterate through the unix array and store the elements in a pl/sql collection variable. But I am unable to increment the index of the array. Below is my code:
#!/bin/sh
# local variables declaration and initialization
v_username="$1"
v_password="$2"
v_database="$3"
v_vdsl_file="$4"
IFS=$'\n'
set -f
counter=0
declare -a v_vdsl_id
for i in $(cat $v_vdsl_file); do
v_vdsl_id[$counter]=`echo "$i"`
counter=$(($counter+1))
done;
p=0
conn1=`sqlplus -s ${v_username}/${v_password}@${v_database}<<THEEND
SET HEAD OFF
SET AUTOPRINT OFF
SET ECHO OFF
SET VERIFY OFF
SET FEEDBACK OFF
SET LINESIZE 3000
SET WRAP OFF
SET serveroutput on
DECLARE
counter integer :=0;
type table_vdsl_id is table of integer;
vdsl_oids table_vdsl_id := table_vdsl_id();
begin
for i in 1..${#v_vdsl_id[*]}
loop
counter := counter +1;
vdsl_oids.extend;
vdsl_oids(counter) := ${v_vdsl_id[$p]};
${p} := ${p} +1;
end loop;
end;
/
THEEND`
The error is faced while trying to increment the unix variable counter:
0 := 0 +1;
*
ERROR at line 88:
ORA-06550: line 88, column 9:
PLS-00103: Encountered the symbol "0" when expecting one of the following:
( begin case declare end exit for goto if loop mod null
The ${p} basically picks up the value of p, but how do I change the value of this unix counter in the sql block? Please advise.