Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PL/SQL Object Type Usage (OOP)

Status
Not open for further replies.

jtanner

Technical User
Feb 18, 2007
39
US
Hello,

In an Oracle 10g database I am trying to learn how to use Objects in PL/SQL. I have to say the code examples in the docs leave much to the imagination.

I thought, let me try to emulate a simple msgbox() object. I want to initialize it, set a property value and then extract a property value. I feel like I am a million miles away.

Psuedo Code thus far ...
Code:
create or replace TYPE msgbox AS OBJECT (
   Title   varchar2(50),
   Message varchar2(500),
   MEMBER FUNCTION setMsg(pTitle IN varchar2 DEFAULT 'msgbox()') RETURN msgbox,
   MEMBER PROCEDURE displayMsg 
);

create or replace TYPE BODY msgbox AS
MEMBER FUNCTION setMsg(pTitle IN varchar2) RETURN msgbox AS
oMsgBox msgbox := SELF; -- initialize to "current" object
BEGIN
   oMsgBox.Title := pTitle;
   RETURN oMsgBox;
END;

MEMBER PROCEDURE displayMsg AS
   BEGIN
      htp.p(oMsgBox.Title);
   END;
END;

create or replace PROCEDURE TESTM AS
   mb msgbox := new msgbox('Title','Message');
BEGIN
   mb.setMsg('My Title','My Messsage.');
   htp.p( mb.displayMsg() );
EXCEPTION
   WHEN OTHERS THEN
   htp.p('An error has occured on this page.');
END TESTM;

Can anyone please share how you have coded set and get values and called a method from a standard PL/SQL procedure or function?

Thanks for you advice,

JT
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top