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

  • SEARCH
  • Home
  • 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 6603313
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 25, 20262026-05-25T18:59:33+00:00 2026-05-25T18:59:33+00:00

Have this objects and table types: CREATE TYPE Person_typ AS OBJECT ( name CHAR(20),

  • 0

Have this objects and table types:

CREATE TYPE Person_typ AS OBJECT
( 
    name CHAR(20),
    ssn CHAR(12),
    address VARCHAR2(100)
);

CREATE TYPE Person_nt IS TABLE OF Person_typ;

CREATE TYPE dept_typ AS OBJECT
( 
    mgr Person_typ,
    emps Person_nt,
    MEMBER PROCEDURE getEmp(name IN  CHAR(20)),
);

CREATE TABLE dept OF dept_typ;

How i can get the employer with the function getEmp and argument name ?

CREATE TYPE BODY dept_typ AS 
   MEMBER  PROCEDURE getEmp(name IN CHAR(20)),
   BEGIN
      ????? What i put where ????
   END;
END;

My problem is that i can’t make self.emps like I can do with self.mgr … and i don’t know why….

Thanks,
Joao

  • 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-05-25T18:59:34+00:00Added an answer on May 25, 2026 at 6:59 pm

    My guess is that you want something like this

    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE TYPE dept_typ AS OBJECT
      2  (
      3      mgr Person_typ,
      4      emps Person_nt,
      5      MEMBER FUNCTION getEmp(p_name IN  VARCHAR2)
      6               RETURN person_typ
      7* );
    SQL> /
    
    Type created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1   CREATE OR REPLACE TYPE BODY dept_typ AS
      2      MEMBER FUNCTION getEmp(p_name IN VARCHAR2)
      3               RETURN person_typ
      4      AS
      5      BEGIN
      6         for i in 1 .. self.emps.count()
      7         loop
      8           if( self.emps(i).name = p_name )
      9           then
     10             return self.emps(i);
     11           end if;
     12         end loop;
     13      END;
     14*  END;
    SQL> /
    
    Type body created.
    
    1. If you want getEmp to return something, it should be a function.
      You could also, I suppose, define it as a procedure with an OUT
      parameter but that’s generally not what you want.
    2. Input and output parameters do not have lengths. You can’t declare a parameter as a CHAR(20). You could declare it as a CHAR or as a VARCHAR2 with no length. But there are essentially no cases where a CHAR would be preferred over a VARCHAR2 and employee names are definitely not one of the cases where it’s even close.
    3. There is no comma after the declaration of the member function or procedure in either the type spec or the type body. You also need an IS or an AS in the definition of the member function or procedure in the type body.
    4. Since PERSON_NT is a collection, you need to iterate over the collection. Note here that I’m assuming that the collection is dense in this code. You could use the FIRST and NEXT methods on the collection to loop over the elements in a sparse collection as well.

    If you really want to select from the collection, you’d need to use the TABLE operator. This approach, however, is less efficient and generally more cumbersome than simply iterating over the collection.

    SQL> ed
    Wrote file afiedt.buf
    
      1   CREATE OR REPLACE TYPE BODY dept_typ AS
      2      MEMBER FUNCTION getEmp(p_name IN VARCHAR2)
      3               RETURN person_typ
      4      AS
      5      BEGIN
      6         for i in (select * from table(self.emps))
      7         loop
      8           if( i.name = p_name )
      9           then
     10             return new person_typ( i.name, i.ssn, i.address );
     11           end if;
     12         end loop;
     13      END;
     14*  END;
    SQL> /
    
    Type body created.
    

    If you want to add elements to the collection (assuming the collection has previously been initialized)

    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE TYPE dept_typ AS OBJECT
      2  (
      3      mgr Person_typ,
      4      emps Person_nt,
      5      MEMBER FUNCTION getEmp(p_name IN  VARCHAR2)
      6               RETURN person_typ,
      7      MEMBER PROCEDURE addEmp( p_person IN person_typ )
      8* );
    SQL> /
    
    Type created.
    
    SQL> ed
    Wrote file afiedt.buf
    
      1  CREATE OR REPLACE TYPE BODY dept_typ AS
      2     MEMBER FUNCTION getEmp(p_name IN VARCHAR2)
      3              RETURN person_typ
      4     AS
      5     BEGIN
      6        for i in 1 .. self.emps.count()
      7        loop
      8          if( self.emps(i).name = p_name )
      9          then
     10            return self.emps(i);
     11          end if;
     12        end loop;
     13     END;
     14    MEMBER PROCEDURE addEmp(p_person IN person_typ)
     15    AS
     16    BEGIN
     17      self.emps.extend();
     18      self.emps(self.emps.count) := p_person;
     19    END;
     20* END;
    SQL> /
    
    Type body created.
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have this test case def setUp(self): self.user = User.objects.create(username=tauri, password='gaul') def test_loginin_student_control_panel(self): c
I have this huge domain object(say parent) which contains other domain objects. It takes
I'm trying to create instances of objects that have the same base type like
I have this situation where I want to display a list of Administration objects
I have a DLL with some COM objects . Sometimes, this objects crashes and
Using Dozer to map two objects, I have: /** /* This first class uses
I want to have immutable Java objects like this (strongly simplified): class Immutable {
If I have code with nested objects like this do I need to use
I'm doing this query: SomeObject.objects.annotate(something=Avg('something')).order_by(something).all() I normally have an aggregate field in my model
I have List objects which are shown like this: www.mysite.com/lists/123 Where 123 is the

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.