views:

42

answers:

2

Hi all

Oracle & objects:

I have a table that contain more than one type of object (by using inheritance),but i want to know the actual type of each (using loop and ?). Is there a function like isInstanceOf() here?

plz provide an example

Thanks in Advance

+2  A: 

What you want is the OF TYPE clause.

APC
A: 

CREATE OR REPLACE TYPE TEST_OBJ AS OBJECT (
  field1  VARCHAR2(20),
  field2  NUMBER(10)
);

Then you can use the SYS.ANYDATA type.


DECLARE
   t_test_obj TEST_OBJ;
   v_anydata SYS.ANYDATA; 
BEGIN
    t_test_obj := TEST_OBJ('ABC',123);
    v_anydata := SYS.ANYDATA.ConvertObject(t_test_obj);
    DBMS_OUTPUT.PUT_LINE('OBJECT TYPE IS : '||v_anydata.GetTypeName());
END;
David