Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Usenet -> c.d.o.misc -> Re: Beginner problem with assigning object methods.

Re: Beginner problem with assigning object methods.

From: Phil Singer <psinger1_at_chartermi.net>
Date: Fri, 26 Dec 2003 23:00:10 -0500
Message-ID: <3FED03CA.C9E420D4@chartermi.net>


Doobai wrote:
>
> Hi, hope you can help,
>
> Just starting to learn about objects-relationals and I've come across
> what I hope is a little problem, when I try and make the method code,
> I get told the type already exists, heres a stripped down example, I'm
> sure its a terribly simple mistake:
>

The problem is in translating the O-O terminology you are familiar with to what Oracle uses.

Oracle 'Object' -> Something (anything) stored in the database.

Oracle Type -> The data part of an O-O class.

Oracle Package (or function or procedure) -> The method part of an

    O-O class

[and what I don't know about O-O programming will fill 5 flames]

> -- Example object type [works fine]:
>
> CREATE OR REPLACE TYPE student_type as object
> (firstName varchar2(25),
> MEMBER FUNCTION getName RETURN varchar2,
> PRAGMA RESTRICT_REFERENCES (getName, WNDS, WNPS, RNDS, RNPS))
> /

What you have created here looks like a package specification to me.
>
> -- Example object body type:
>
> CREATE TYPE BODY student_type IS
> MEMBER FUNCTION getName RETURN VARCHAR2 IS
> BEGIN
> RETURN SELF.firstName;
> END;
> END;
> /
>

And this looks like a package body
> -- Error I get is:
>
> ERROR at line 1:
> ORA-00955: name is already used by an existing object
>

Please note that compiling a package specification is mostly a case of getting things syntactically correct. It does not mean that the semantics are anywhere near correct.

In other words, the fact that your package specification worked as an object type definition is interesting, but should not be taken to indicate that you are on the right track.

> All I want to do (for now) is just to get the info out of the object,
> like
>
> create table student of student_type;
> select s.getName() from student s;
>
> If I can get this test working then I can finally progress on, I
> understand that student_type does exist, but surely (and from the
> examples im reading) I need to specify where this method belongs.
>
> Thanks,
>
> Doobai.

-- 
Phil Singer                |    psinger1ATchartermiDOTnet
Oracle DBA
Remove the Obvious to reply
Received on Fri Dec 26 2003 - 22:00:10 CST

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US