Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

typeof Equivalent for Object Types in PL/SQL

I'm trying to use OOP and TDD inside of Oracle. Yes, I know that sounds crazy. And, I need some advice.

I'm writing a test for the following constructor method (simplified for the purposes of this question):

CONSTRUCTOR FUNCTION PERSON(p_pidm NUMBER, p_throw_exception NUMBER DEFAULT 0, p_program_id NUMBER DEFAULT 0)
RETURN SELF AS RESULT IS

BEGIN

    -- Attach constructor parameters to internal attributes
    self.throw_exception := p_throw_exception;
    self.program_id := p_program_id;

    -- TESTING STUDENT INSTANTIATION
    self.student := NEW STUDENT(self.a_pidm);

    RETURN;
END;

In the corresponding test, I'll need to verify that self.student is set to a valid instance of STUDENT. In other languages, I do this with a typeof method, but I'm not aware of one in PL/SQL.

So, the question is, does anyone know a function/procedure that I can pass a user-defined type into and get back its class/type name?

Thanks.

like image 202
eikonomega Avatar asked Feb 28 '26 23:02

eikonomega


1 Answers

You probably want to use the IS OF <<type>> syntax.

Something like

IF l_variable IS OF( student )
THEN
  <<do something>>
END IF;
like image 124
Justin Cave Avatar answered Mar 02 '26 14:03

Justin Cave