Unable to get values from associative arrays into a different procedure [message #650419] |
Mon, 25 April 2016 00:04 |
buggleboy007
Messages: 282 Registered: November 2010 Location: Canada
|
Senior Member |
|
|
I am experiencing an issue when trying to call a procedure outside. This procedure takes an input parameter and sends out a collection type.
Basically I am either unable to call the values outside of the procedure and the count outside of the procedure returns null.
can any one help me with this issue.
The code is as follows:
The following portion is declared in a package specification and is:
TYPE numberofdays_aa IS RECORD
(tablename IRF_PURGE_CNTRL_PRCS.purge_cntrl_table_nm%TYPE ,
numberofdays IRF_PURGE_CNTRL_PRCS.purged_cntrl_value_qty%TYPE);
TYPE la_noofdays_aa IS TABLE OF numberofdays_aa INDEX BY PLS_INTEGER;
In the package body the following code exists:
Firstly I created a local procedure (with forward declarations on the top in my package body) which is as follows:
PROCEDURE getnoofdays(g_PURGE_CNTRL_CD1 IN IRF_PURGE_CNTRL_PRCS.purge_cntrl_cd%TYPE,
p_tOuttablename OUT la_noofdays_aa)
IS
lv_Num_index PLS_INTEGER;
BEGIN
SELECT purge_cntrl_table_nm,purged_cntrl_value_qty
BULK COLLECT INTO lv_aa_noofdays
FROM irf_purge_cntrl_prcs
WHERE purge_cntrl_cd = g_PURGE_CNTRL_CD1
AND purge_cntrl_table_nm <> 'CMF_EDI_ERR_PURGE';
lv_Num_index:=lv_aa_noofdays.COUNT;
DBMS_OUTPUT.put_line(to_char(lv_Num_index));
FOR I in lv_aa_noofdays.FIRST..lv_aa_noofdays.LAST
LOOP
DBMS_OUTPUT.put_line(to_char(lv_aa_noofdays(I).tablename) ||'-'||to_char(lv_aa_noofdays(I).numberofdays));
END LOOP;
END;
I compiled it and it compiled successfully.
Then I am trying to call this procedure in a different area of the same package body and I am using the following code:
p_tOuttblnm la_noofdays_aa;
--***********SAMPLE TESTING TO GET INTO AN ARRAY****************************
getnoofdays(g_PURGE_CNTRL_CD1, p_tOuttblnm);
FOR nIndex IN 1..p_tOuttblnm.COUNT LOOP
DBMS_OUTPUT.put_line(TO_CHAR(p_tOuttblnm(nIndex).tablename)||'-'||TO_CHAR(p_tOuttblnm(nIndex).numberofdays));
END LOOP;
--***********************************************************************
Once the cursor comes out of the above procedure it does not even go into the "FOR LOOP". My intention is to bring the two values
(which come out of the SELECT QUERY ) AND put them into the above DBMS_OUTPUT.put_line (the 2nd one; and not the one in the procedure as I am able to fetch the values there).
Can any one help me please?
|
|
|
|
|
|
|
|
|
Re: Unable to get values from associative arrays into a different procedure [message #650442 is a reply to message #650441] |
Mon, 25 April 2016 09:45 |
buggleboy007
Messages: 282 Registered: November 2010 Location: Canada
|
Senior Member |
|
|
BlackSwan wrote on Mon, 25 April 2016 08:59Problem Exists Between Keyboard And Chair
BS: If you don't wish to help that's fine. You can even ignore my posts henceforth. But posting nonsense comments such as what you have posted is completely uncalled for. I know I am weak in collections and Oracle being a vast ocean there are lots of things that I need to learn. I am aware of this.
Besides when you have put me on ignore list, you should not even be wasting your time trying to comment on my flawed code. You just come off as an ass.
Remember silence is golden. If all you know is only to criticize, then I would suggest that you just shut up and move on to other posts. Anyways thanks for your wonderful piece of advice.
|
|
|
Re: Unable to get values from associative arrays into a different procedure [message #650460 is a reply to message #650419] |
Mon, 25 April 2016 15:36 |
|
Barbara Boehmer
Messages: 9088 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
In your getnoofdays procedure you have done bulk collect into lv_aa_noofdays which has not been declared anywhere. You have not populated the out parameter p_tOuttablename of the getnoofdays procedure anywhere. So, when you call getnoofdays from your different procedure, it isn't receiving anything. Please see the corrected code below, with some assumptions, since you did not provide full code.
SCOTT@orcl> CREATE TABLE irf_purge_cntrl_prcs
2 (purge_cntrl_table_nm VARCHAR2(30),
3 purged_cntrl_value_qty NUMBER,
4 purge_cntrl_cd NUMBER)
5 /
Table created.
SCOTT@orcl> INSERT ALL
2 INTO irf_purge_cntrl_prcs VALUES ('table1', 10, 1)
3 INTO irf_purge_cntrl_prcs VALUES ('table2', 20, 1)
4 INTO irf_purge_cntrl_prcs VALUES ('CMF_EDI_ERR_PURGE', 30, 1)
5 INTO irf_purge_cntrl_prcs VALUES ('table4', 40, 4)
6 SELECT * FROM DUAL
7 /
4 rows created.
SCOTT@orcl> CREATE OR REPLACE PACKAGE your_package
2 AS
3 TYPE numberofdays_aa IS RECORD
4 (tablename IRF_PURGE_CNTRL_PRCS.purge_cntrl_table_nm%TYPE ,
5 numberofdays IRF_PURGE_CNTRL_PRCS.purged_cntrl_value_qty%TYPE);
6 TYPE la_noofdays_aa IS TABLE OF numberofdays_aa INDEX BY PLS_INTEGER;
7 PROCEDURE getnoofdays
8 (g_PURGE_CNTRL_CD1 IN IRF_PURGE_CNTRL_PRCS.purge_cntrl_cd%TYPE,
9 p_tOuttablename OUT la_noofdays_aa);
10 PROCEDURE different_procedure
11 (g_PURGE_CNTRL_CD1 IN IRF_PURGE_CNTRL_PRCS.purge_cntrl_cd%TYPE);
12 END your_package;
13 /
Package created.
SCOTT@orcl> SHOW ERRORS
No errors.
SCOTT@orcl> CREATE OR REPLACE PACKAGE BODY your_package
2 AS
3 PROCEDURE getnoofdays
4 (g_PURGE_CNTRL_CD1 IN IRF_PURGE_CNTRL_PRCS.purge_cntrl_cd%TYPE,
5 p_tOuttablename OUT la_noofdays_aa)
6 IS
7 lv_aa_noofdays la_noofdays_aa;
8 lv_Num_index PLS_INTEGER;
9 BEGIN
10 SELECT purge_cntrl_table_nm,purged_cntrl_value_qty
11 BULK COLLECT INTO lv_aa_noofdays
12 FROM irf_purge_cntrl_prcs
13 WHERE purge_cntrl_cd = g_PURGE_CNTRL_CD1
14 AND purge_cntrl_table_nm <> 'CMF_EDI_ERR_PURGE';
15
16 lv_Num_index:=lv_aa_noofdays.COUNT;
17
18 DBMS_OUTPUT.put_line(to_char(lv_Num_index));
19
20 FOR I in 1..lv_aa_noofdays.COUNT
21 LOOP
22 DBMS_OUTPUT.put_line(to_char(lv_aa_noofdays(I).tablename) ||'-'||to_char(lv_aa_noofdays(I).numberofdays));
23 END LOOP;
24
25 p_tOuttablename := lv_aa_noofdays;
26 END getnoofdays;
27
28 PROCEDURE different_procedure
29 (g_PURGE_CNTRL_CD1 IN IRF_PURGE_CNTRL_PRCS.purge_cntrl_cd%TYPE)
30 IS
31 p_tOuttblnm la_noofdays_aa;
32 BEGIN
33 getnoofdays(g_PURGE_CNTRL_CD1, p_tOuttblnm);
34
35 FOR nIndex IN 1..p_tOuttblnm.COUNT LOOP
36 DBMS_OUTPUT.put_line(TO_CHAR(p_tOuttblnm(nIndex).tablename)||'-'||TO_CHAR(p_tOuttblnm(nIndex).numberofdays));
37 END LOOP;
38 END different_procedure;
39 END your_package;
40 /
Package body created.
SCOTT@orcl> SHOW ERRORS
No errors.
SCOTT@orcl> EXEC your_package.different_procedure (1)
2
table1-10
table2-20
table1-10
table2-20
PL/SQL procedure successfully completed.
SCOTT@orcl> EXEC your_package.different_procedure (5)
0
PL/SQL procedure successfully completed.
|
|
|
Re: Unable to get values from associative arrays into a different procedure [message #650736 is a reply to message #650460] |
Mon, 02 May 2016 09:22 |
buggleboy007
Messages: 282 Registered: November 2010 Location: Canada
|
Senior Member |
|
|
[quote]Barbara Boehmer wrote on Mon, 25 April 2016 15:36In your getnoofdays procedure you have done bulk collect into lv_aa_noofdays which has not been declared anywhere. You have not populated the out parameter p_tOuttablename of the getnoofdays procedure anywhere. So, when you call getnoofdays from your different procedure, it isn't receiving anything. Please see the corrected code below, with some assumptions, since you did not provide full code.
Thanks Barbara for all your assistance. You are correct - I was not populating the values of lv_aa_noofdays back into the OUT parameter. Hence I was stuck.I checked your code, understood and tried it myself. It's working fine now. In fact I changed it a bit to make the necessary corrections as well. Here's what I have now:
PROCEDURE getnoofdays(g_PURGE_CNTRL_CD1 IN IRF_PURGE_CNTRL_PRCS.purge_cntrl_cd%TYPE,
p_tOuttablename OUT la_noofdays_aa)
IS
lv_aa_noofdays la_noofdays_aa;
lv_Num_index PLS_INTEGER;
BEGIN
SELECT purge_cntrl_table_nm,purged_cntrl_value_qty
BULK COLLECT INTO lv_aa_noofdays
FROM irf_purge_cntrl_prcs
WHERE purge_cntrl_cd = g_PURGE_CNTRL_CD1
AND purge_cntrl_table_nm <> 'CMF_EDI_ERR_PURGE';
lv_Num_index:=lv_aa_noofdays.COUNT;
FOR I in 1..lv_Num_index
LOOP
--DBMS_OUTPUT.put_line(TO_CHAR(lv_aa_noofdays(I).tablename)||'-'||TO_CHAR(lv_aa_noofdays(I).numberofdays));
p_tOuttablename(I).tablename:=lv_aa_noofdays(I).tablename;
p_tOuttablename(I).numberofdays:=lv_aa_noofdays(I).numberofdays;
END LOOP;
END getnoofdays;
Apologies for my delayed response as I was sick the whole of last week.
Thanks once again Barbara for all your assistance.
|
|
|
Re: Unable to get values from associative arrays into a different procedure [message #650741 is a reply to message #650736] |
Mon, 02 May 2016 14:29 |
|
Barbara Boehmer
Messages: 9088 Registered: November 2002 Location: California, USA
|
Senior Member |
|
|
I am glad that it worked for you and hope you're feeling better. I don't know if what you have posted is a simplification of the real problem, so I don't know if you need all of the variables for some other processing. If not, then you can eliminate some by just selecting directly into the out parameter. Please see the simplified code below.
PROCEDURE getnoofdays
(g_PURGE_CNTRL_CD1 IN IRF_PURGE_CNTRL_PRCS.purge_cntrl_cd%TYPE,
p_tOuttablename OUT la_noofdays_aa)
IS
BEGIN
SELECT purge_cntrl_table_nm,purged_cntrl_value_qty
BULK COLLECT INTO p_tOuttablename
FROM irf_purge_cntrl_prcs
WHERE purge_cntrl_cd = g_PURGE_CNTRL_CD1
AND purge_cntrl_table_nm <> 'CMF_EDI_ERR_PURGE';
END getnoofdays;
[Updated on: Mon, 02 May 2016 14:32] Report message to a moderator
|
|
|
Re: Unable to get values from associative arrays into a different procedure [message #650746 is a reply to message #650741] |
Mon, 02 May 2016 20:08 |
buggleboy007
Messages: 282 Registered: November 2010 Location: Canada
|
Senior Member |
|
|
As I am implementing the concept of Collections(with every author of a PL/SQL book doing it in a different format/style) for the very first time in my project, ideas such as yours are significantly a step in the right direction as far as I am concerned.
Yes, I agree there are a couple of unwanted variables and things that are not likely to be used, should not be in the code. I will give your idea a try Barbara and let you know the results.
|
|
|