Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Associative Arrays (Index By Pl Sql Table) With Cursor

user10799880Jan 15 2009 — edited Jan 15 2009
Hi ,
My Requirement is that I want to use associative arrays (Or Index By Pl Sql Table) and value of subscript should match with the value of column1 value in cursor. This cursor is actually used to populate associative collection.

Please note I specifically want to use the associative array(Index By table) due to below mentioned 2 reasons :-
<ol>
<li>Only In Associative arrays can be non sequential.</li>
<li>Only in Associative arrays I can directly reference values (If i know subscript) and I don't need to scan the entire array to reach to desired subscript in array.
</li>
</ol>
<p>

Below is the Code I am using and<em><strong> <font color="#ff0000">my requirement is Associative_Array(Index).Col1 = Index</font></strong></em>
</p>
<p>
----------------------------------------------------------------------------------
</p>
<p>
CREATE OR REPLACE PROCEDURE GDWAPPADM.Collection_Test_Ver2
IS
TYPE recIndividualBehaviour IS RECORD
(
INB_IN_ID_FK INB_INDIVIDUAL_BEHAVIOUR_DM.INB_IN_ID_FK%TYPE,
INB_ENR_ALERTREG_TOT INB_INDIVIDUAL_BEHAVIOUR_DM.INB_ENR_ALERTREG_TOT%TYPE,
INB_ENR_ALERTREG_DATE INB_INDIVIDUAL_BEHAVIOUR_DM.INB_ENR_ALERTREG_DATE%TYPE
) ;


TYPE tabIndividualBehaviour IS TABLE OF recIndividualBehaviour INDEX BY BINARY_INTEGER ;

TYPE RefCursor IS REF CURSOR ;

vProc_Msg_Cntr NUMBER :=0;
Counter1 NUMBER :=0;
LoopCounter NUMBER;
pIndividualBehaviour tabIndividualBehaviour;
vSql VARCHAR2(30000);
cRefCursor RefCursor;

--------------------------------------------------------------------------------------------------------------------------
vIn_Id_Fk INB_INDIVIDUAL_BEHAVIOUR_DM.INB_IN_ID_FK%TYPE;
vEnr_AlertReg_Tot INB_INDIVIDUAL_BEHAVIOUR_DM.INB_ENR_ALERTREG_TOT%TYPE;
vMax_Enr_Start_Date INB_INDIVIDUAL_BEHAVIOUR_DM.INB_ENR_ALERTREG_DATE%TYPE;

--------------------------------------------------------------------------------------------------------------------------

Cursor cCursor Is
Select
DISTINCT CI_IN_ID_FK INB_IN_ID_FK, NULL INB_ENR_ALERTREG_TOT, NULL INB_ENR_ALERTREG_DATE From CI_COMPOSITE_INDIVIDUAL_DM;


BEGIN
Select CI_IN_ID_FK Into vIn_Id_Fk From CI_COMPOSITE_INDIVIDUAL_DM Where Rownum=1;
DBMS_Output.Put_Line('Value Of vIn_Id_Fk ::' || vIn_Id_Fk );

Open cCursor;
Loop
FETCH cCursor BULK COLLECT INTO
pIndividualBehaviour
Limit 25000;
<em><font color="#ff0000">----- Please Note I have already tried to use " Fetch cCursor Bulk Collect Into pIndividualBehaviour(cCursor.INB_IN_ID_FK) limit 25000; " But I am getting error as invalid cursor reference.</font></em>
</p>
<p>

EXIT WHEN cCursor%NOTFOUND;
END LOOP;
CLOSE cCursor;

DBMS_Output.Put_Line('Value Of Added In_Id_Fk At Position pIndividualBehaviour('||vIn_Id_Fk ||') Is ::' || pIndividualBehaviour(vIn_Id_Fk ).INB_IN_Id_Fk);
END;
/
</p>
<p>
<font color="#ff0000">==&gt; If I comment the last DBS_Output then the procedure works fine but not with it.</font>
</p>
<p>
<font color="#ff0000">==&gt; I always want to ensure that for every record in Associative Array pIndividualBehaviour </font><font color="#0000ff"><strong><font color="#000000">"subscript/index value"</font> should be same as value of <font color="#000000">"pIndividualBehaviour(vIn_Id_Fk ).INB_IN_Id_Fk
"</font></strong></font>
</p>
<p>
Thanks In advance,
</p>
<p>
Manish
</p>

Comments

Processing
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Feb 12 2009
Added on Jan 15 2009
9 comments
1,034 views