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 9143851
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 17, 20262026-06-17T10:07:32+00:00 2026-06-17T10:07:32+00:00

This is a follow-up question to Is it possible to use object composition in

  • 0

This is a follow-up question to Is it possible to use object composition in PL/SQL?

That question addressed how to create object types in PL/SQL which are mutually dependent (i.e. one attribute of each object is a reference to the other object).

The next problem that I’ve encountered has to do with the object constructors. Here’s the code (logically, student exists inside of person). Also, just to preclude this in the comments, using inheritance is not an option for me.

Person Object

CREATE OR REPLACE TYPE PERSON FORCE AUTHID DEFINER UNDER MYSCHEMA.BASE_OBJECT (
    student MYSCHEMA.student,
    additional attributes...

    CONSTRUCTOR FUNCTION PERSON
    RETURN SELF AS RESULT

) NOT FINAL; 

CREATE OR REPLACE TYPE BODY PERSON
AS
    CONSTRUCTOR FUNCTION PERSON
    RETURN SELF AS RESULT IS

    BEGIN
        self.student := NEW MYSCHEMA.STUDENT(self);
        RETURN;
    END;
END;

Student Object

CREATE OR REPLACE TYPE STUDENT FORCE AUTHID DEFINER UNDER MYSCHEMA.BASE_OBJECT (
    person REF MYSCHEMA.PERSON,

    CONSTRUCTOR FUNCTION STUDENT(p_person REF MYSCHEMA.PERSON)
    RETURN SELF AS RESULT

) NOT FINAL; 

CREATE OR REPLACE TYPE BODY STUDENT
AS

    CONSTRUCTOR FUNCTION STUDENT(p_person REF MYSCHEMA.PERSON)
    RETURN SELF AS RESULT IS

    BEGIN
        self.person := p_person;
        RETURN;
    END;
END;

This code will compile without any errors except for the following line within the PERSON constructor which instantiates a STUDENT object inside of PERSON:

self.student := NEW MYSCHEMA.STUDENT(self);

Which throws the following error:

Error(22,29): PLS-00306: wrong number or types of arguments in call to 'STUDENT'

And so, dear friends, I seek your help again. I’m guessing that there is an additional parameter that is being passed implicitly into the STUDENT constructor, but that’s just a guess.

Thanks.

  • 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-17T10:07:34+00:00Added an answer on June 17, 2026 at 10:07 am

    A REF must refer to a row. You cannot pass SELF, since it is not a reference.

    One way to make this work is to create a hidden table:

    create table shadow_person of person;
    

    And every instance secrently creates a row in that table:

    CONSTRUCTOR FUNCTION PERSON
    RETURN SELF AS RESULT IS
        v_ref_person ref person;
    BEGIN
        insert into shadow_person values(self)
        returning make_ref(shadow_person, object_id) into v_ref_person;
    
        self.a_student := new student(v_ref_person);
    
        RETURN;
    END;
    

    This seems to work, but probably has really horrible side-affects that nobody would want in a real production environment.

    Here’s the full script:

    drop type base_object force;
    drop type student force;
    drop type person force;
    drop table shadow_person;
    
    
    create or replace type base_object is object (a varchar2(10)) not final;
    /
    
    CREATE OR REPLACE TYPE PERSON FORCE AUTHID DEFINER UNDER BASE_OBJECT (
        b varchar2(10),
        CONSTRUCTOR FUNCTION PERSON RETURN SELF AS RESULT
    ) NOT FINAL; 
    /
    
    CREATE OR REPLACE TYPE STUDENT FORCE AUTHID DEFINER UNDER BASE_OBJECT (
        c varchar2(10),
        a_person REF PERSON,
        CONSTRUCTOR FUNCTION STUDENT(p_person ref PERSON) RETURN SELF AS RESULT
    ) NOT FINAL; 
    /
    
    alter type person add attribute a_student student cascade;
    
    create table shadow_person of person;
    
    CREATE OR REPLACE TYPE BODY PERSON
    AS
        CONSTRUCTOR FUNCTION PERSON
        RETURN SELF AS RESULT IS
            v_ref_person ref person;
        BEGIN
            insert into shadow_person values(self)
            returning make_ref(shadow_person, object_id) into v_ref_person;
    
            self.a_student := new student(v_ref_person);
    
            RETURN;
        END;
    END;
    /
    
    CREATE OR REPLACE TYPE BODY STUDENT
    AS
        CONSTRUCTOR FUNCTION STUDENT(p_person REF PERSON)
        RETURN SELF AS RESULT IS
        BEGIN
            self.a_person := p_person;
            RETURN;
        END;
    END;
    /
    
    
    --Example of how to use it:
    declare
        v_person person := person;
    begin
        v_person.a := 'person a';
        v_person.b := 'b';
        v_person.a_student.a := 'student a';
        v_person.a_student.c := 'c';
    
        dbms_output.put_line(v_person.a_student.c);
    end;
    /
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

Just a follow up question to this one here => link Is it possible
I have a follow up question to this question . Is it possible to
This is a follow up question from Calling constructor in return statement . This
This is a follow up question to a previous question I asked about calculating
This is a follow-on question from the one I asked here . Can constraints
This is a follow-up question to ASP.NET How to pass container value as javascript
This is a follow-up question to this question I asked earlier. Btw thanks Neil
this is a follow-up question of mine. Suppose now I have a URL :
This is a follow-up question to the following if you would like to see:
This is a follow-up question related to my previous post . Below is a

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.