I read about IS OF TYPE and I expected that it should return TRUE, FALSE or NULL.
I have two object types:
CREATE TYPE o1 AS OBJECT ( id NUMBER );
/
CREATE TYPE o2 AS OBJECT ( id NUMBER );
/
When I run the code below, everything is OK.
DECLARE
type1 o1;
BEGIN
type1 := o1(id=>1);
if (type1 IS OF (o1)) then
DBMS_OUTPUT.PUT_LINE('type1 is o1');
END if;
END;
/
But when I try to run:
DECLARE
type1 o1;
BEGIN
type1 := o1(id=>1);
if (type1 IS OF (o2)) then
DBMS_OUTPUT.PUT_LINE('type1 is o1');
END if;
END;
/
I received the following exceptions
Error report:
ORA-06550: line 6, column 21:
PLS-00382: expression is of wrong type
ORA-06550: line 6, column 4:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
In the documentation there isn’t clear explanation, should I catch exception if something is of the wrong type? Or, should I expect false in the IF condition?
If you have declared your variable as
O1type then you can useis of [type]condition to test only whether your variable is ofo1type or is ofo1‘s subtype. Here is an example(variables must be instantiated):Update:
Take a look at this to get more information about
is of[type]. Usually data type of a variable is known at compile time, but if you have to deal with dynamic typing you may look atanydata(object data type). Here is a simple example: