Home » SQL & PL/SQL » SQL & PL/SQL » Declare private attribute of Object type
Declare private attribute of Object type [message #187498] Mon, 14 August 2006 04:24 Go to next message
nvd077
Messages: 6
Registered: July 2006
Junior Member
Can i have an private attribute in object type?

please for help

best regards
Re: Declare private attribute of Object type [message #187591 is a reply to message #187498] Mon, 14 August 2006 10:19 Go to previous messageGo to next message
markmal
Messages: 113
Registered: April 2006
Location: Toronto, Canada
Senior Member
You can declare members in a class body. These will be visible only for other members of this class.
Re: Declare private attribute of Object type [message #187676 is a reply to message #187498] Mon, 14 August 2006 20:58 Go to previous messageGo to next message
nvd077
Messages: 6
Registered: July 2006
Junior Member
Thank for your helping. But i don't know how to declare member attribute in object body.
Can you give me a sample?

Best regards.
Re: Declare private attribute of Object type [message #187703 is a reply to message #187498] Tue, 15 August 2006 01:12 Go to previous messageGo to next message
hobbes
Messages: 173
Registered: January 2006
Senior Member
To my knowledge Oracle object types do not support private attributes in the TYPE BODY; attributes must be defined in the TYPE specification only and have the implicit visibility of public.

Re: Declare private attribute of Object type [message #187827 is a reply to message #187498] Tue, 15 August 2006 20:35 Go to previous messageGo to next message
markmal
Messages: 113
Registered: April 2006
Location: Toronto, Canada
Senior Member
Yes, Hobbes is right. I mixed it up with packages. Embarassed
However, if the intention of having the private attributes is to produce a "cleaner" code, where the type declaration is not cluttered with attributes that supposed to sit inside a type body, then, in this case, the packages can help as a workaround. Just keep "private" variables inside some package declaration.

[code]
create or replace package P_Test_priv_area as
N number ;
end;
/

create or replace type T_test is object(
pubN number,
member procedure setPriv(p number),
member function getPriv return number
);
/

create or replace type body T_test is

member procedure setPriv(p number) is
begin
P_Test_priv_area.N := p;
end;

member function getPriv return number as
begin
return P_Test_priv_area.N;
end;
end;
/

declare o T_Test; n number;
begin
o := T_Test(null);
o.setPriv(10);
n:=o.getPriv;
dbms_output.put_line('1:'||n);
n:=o.getPriv;
dbms_output.put_line('2:'||n);
end;
/
[code]

Re: Declare private attribute of Object type [message #187851 is a reply to message #187827] Wed, 16 August 2006 00:34 Go to previous message
Frank
Messages: 7880
Registered: March 2000
Senior Member
What if you would have two instances of the object in the same session? They would share the 'private' variable.
I am afraid we have to live with the fact that object types are not yet mature.
Previous Topic: Please kindly help me in this UPDATE command
Next Topic: How to find database name from sqlplus prompt
Goto Forum:
  


Current Time: Fri Dec 09 23:10:44 CST 2016

Total time taken to generate the page: 0.08952 seconds