Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • Home
  • SEARCH
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8900407
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 15, 20262026-06-15T01:05:37+00:00 2026-06-15T01:05:37+00:00

I read about IS OF TYPE and I expected that it should return TRUE,

  • 0

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?

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-15T01:05:38+00:00Added an answer on June 15, 2026 at 1:05 am

    If you have declared your variable as O1 type then you can use is of [type] condition to test only whether your variable is of o1 type or is of o1‘s subtype. Here is an example(variables must be instantiated):

     -- base type  
     SQL> create or replace type o1 as object(
      2    prop number
      3  )not final;
      4  /
    
    Type created
    
    -- O1's subtype
    SQL> create or replace type o2 under o1(
      2    prop1 number
      3  );
      4  /
    
    -- test if the  l_o1 is of O1 type
    SQL> declare
      2    l_o1  o1;
      3  begin
      4    l_o1 := o1(prop=>1);
      5    if l_o1 is of (o1)
      6    then
      7      dbms_output.put_line('Yes');
      8    else
      9      dbms_output.put_line('No');
     10    end if;
     11  end;
     12  /
    
    Yes
    
    PL/SQL procedure successfully completed
    
    -- test if the  l_o1 is of O2 type
    SQL> declare
      2    l_o1  o1;
      3  begin
      4    l_o1 := o1(prop=>1);
      5    if l_o1 is of (o2)
      6    then
      7      dbms_output.put_line('Yes');
      8    else
      9      dbms_output.put_line('No');
     10    end if;
     11  end;
     12  /
    
    No
    
    PL/SQL procedure successfully completed
    
    
    -- test if the  l_o2 is of O2 type
    
    SQL> declare
      2    l_o2  o2;
      3  begin
      4    l_o2 := o2(prop=>1, prop1 => 1);
      5    if l_o2 is of (o2)
      6    then
      7      dbms_output.put_line('Yes');
      8    else
      9      dbms_output.put_line('No');
     10    end if;
     11  end;
     12  /
    
    Yes
    
    PL/SQL procedure successfully completed
    

    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 at anydata(object data type). Here is a simple example:

     SQL> declare
      2    l_o1 o1;
      3  
      4    -- Here is a procedure(for the sake of simplicity has not
      5    -- been written as a schema object)
      6    -- that doesn't not know
      7    -- variable of what dada type will be passed in
      8    -- at compile time;
      9    procedure DoSomething(p_var anydata)
     10    is
     11    begin
     12      case p_var.gettypename
     13        when 'HR.O1'
     14        then dbms_output.put_line('O1 data type. Do something');
     15        when 'HR.O2'
     16        then dbms_output.put_line('O2 data type. Do something');
     17      else
     18        dbms_output.put_line('Unknown data type');
     19      end case;
     20    end;
     21  
     22  begin
     23    l_o1 := o1(prop =>  1);
     24    DoSomething(anydata.ConvertObject(l_o1));
     25  end;
     26  /
    
    O1 data type. Do something
    
    PL/SQL procedure successfully completed
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am talking about type(value)-style casts. The books I have read pass over them
Judging from the information I have read about type providers so far, I wonder
Read about the issue in this stackoverflow question . Still have the same issue
I read about small talk being completely object oriented.. is C++ also completely object
I read about using <context:component-scan base-package=tld.mydomain.business> <context:include-filter type=annotation expression=org.springframework.stereotype.Service/> </context:component-scan> and annotate my service
I read about an inheritance feature in PostgreSQL that seemed pretty neat. Unfortunately I
I read about __packed__ from here and, I understood that when __packed__ is used
I have read the other posts about the notorious _imaging C module error when
I read about JavaScript closures and I thought that I understood it, but apparently
I read the documentation and some articles that talk about the package, but I'm

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.