I am writing a procedure to deal with user defined object which is stored in ANYDATA. The object type and the attribute name can only be known at run time, so I can't define the viarable for it in declare section. In Java, I can use reflection to deal with it, I can know the class name and fields name. Then I can access the fields through reflection. Is there any way to do it in PLSQL like that? What in my head right now is creating an sql string in the procedure dynamically and execute it. But it is not what I want exactly.
Let's say, user A defined a ADT type as create or replace type Person_type as object (fname varchar2(10), lname varchar2(10));
and create an object instance and insert it into ANYDATA.
In my procedure, somehow I know I need to deal with the first attribute of this object, which is fname. So if know the adt type at the first place, my code will be like:
declare
adobject A.Person_type; -- HERE! I don't know the type yet, so I can't define adobject!
tempAnydata anydata;
rt number;
vbuffer varchar2(10);
...
begin
select somecolumn
into tempAnydata
from sometable
where something='something' for update;
rt := tempAnydata.GetObject(adobject);
vbuffer := adobject.fname; -- HERE! I don't know the attribute name is fname!
-- deal with vbuffer here
end;
So what should I do to make it dynamically? Thanks in advance.
tempAnydata
is really anA.person_type
as you surely do (otherwise you couldn't do theGetObject(adobject)
with adobject of exactly this type) then you also know what that type's first attribute is. Or am I missing something? – Cordage