Collection return Null [message #334183] |
Tue, 15 July 2008 13:07  |
Kaeluan
Messages: 179 Registered: May 2005 Location: Montreal, Quebec
|
Senior Member |
|
|
Hello,
we start using object collection not long ago and here is something i don't know why it's not working.
create or replace type test_mfa_ot as object
(
id number(10)
);
CREATE OR REPLACE TYPE liste_test_mfa_ot AS TABLE of test_mfa_ot;
declare
v_liste_mfa liste_test_mfa_ot := new liste_test_mfa_ot();
cursor cur_c1 (p_liste in liste_test_mfa_ot)
is
select id
from table(p_liste);
v_number number;
begin
v_liste_mfa.extend(1);
v_liste_mfa(1).id := 123;
dbms_output.put_line('Test 1:'||v_liste_mfa(1).id);
open cur_c1 (v_liste_mfa);
fetch cur_c1 into v_number;
close cur_c1;
dbms_output.put_line('Test 2:'||v_number);
end;
In this code i was expecting getting the same value in the second dbms_output than in the first one. But instead it seem to return null the second time why?
Thank for helping
|
|
|
Re: Collection return Null [message #334187 is a reply to message #334183] |
Tue, 15 July 2008 13:51   |
ehegagoka
Messages: 493 Registered: July 2005
|
Senior Member |
|
|
hi,
not sure, i think what you mean is this?
declare
v_liste_mfa liste_test_mfa_ot := liste_test_mfa_ot();
v_o test_mfa_ot;
cursor cur_c1 (p_liste in liste_test_mfa_ot)
is
select id
from table(p_liste);
v_number number;
begin
v_o := test_mfa_ot(25);
v_liste_mfa.extend(1);
v_liste_mfa(1) := v_o;
dbms_output.put_line('Test 1:'||v_liste_mfa(1).id);
open cur_c1 (v_liste_mfa);
fetch cur_c1 into v_number;
close cur_c1;
dbms_output.put_line('Test 2:'||v_number);
end;
/
|
|
|
Re: Collection return Null [message #334188 is a reply to message #334183] |
Tue, 15 July 2008 14:02   |
Kaeluan
Messages: 179 Registered: May 2005 Location: Montreal, Quebec
|
Senior Member |
|
|
Ahhh! ok it make sense.
I should not assigne my list directly like this "v_liste_mfa(1).id := 123;"
but instead assign it with the base type of the object like this "v_liste_mfa(1) := new test_mfa_ot(123);"
So this is solving my problem.
Thank a lot
Regards
|
|
|
Re: Collection return Null [message #334191 is a reply to message #334188] |
Tue, 15 July 2008 14:10  |
ehegagoka
Messages: 493 Registered: July 2005
|
Senior Member |
|
|
but i'm still wondering why didnt oracle complained on this:
v_liste_mfa.extend(1);
v_liste_mfa(1).id := 123;
were as you're assigning a value to the first element of the array which is an object that hasn't been instantiated yet =( if someone could explain that =)
|
|
|