Home » SQL & PL/SQL » SQL & PL/SQL » NEW Keyword
NEW Keyword [message #225069] Fri, 16 March 2007 19:56 Go to next message
srinivasocp
Messages: 91
Registered: December 2005
Location: INDIA
Member
HI All,

Can you help me out with this.Why to use the New Keyword(See the below code for better understanding).what does it signify.What makes the difference if i don't use it?

CREATE OR REPLACE TYPE rectangle AS OBJECT
(
-- The type has 3 attributes.
length NUMBER,
width NUMBER,
area NUMBER,
-- Define a constructor that has only 2 parameters.
CONSTRUCTOR FUNCTION rectangle(length NUMBER, width NUMBER)
RETURN SELF AS RESULT
);
/
CREATE OR REPLACE TYPE BODY rectangle AS
CONSTRUCTOR FUNCTION rectangle(length NUMBER, width NUMBER)
RETURN SELF AS RESULT
AS
BEGIN
SELF.length := length;
SELF.width := width;
-- We compute the area rather than accepting it as a parameter.
SELF.area := length * width;
RETURN;
END;
END;
/

DECLARE
r1 rectangle;
r2 rectangle;
BEGIN
r1 := NEW rectangle(10,20,200);
r2 := NEW rectangle(10,20);
END;

[Updated on: Fri, 16 March 2007 19:59]

Report message to a moderator

Re: NEW Keyword [message #225070 is a reply to message #225069] Fri, 16 March 2007 20:11 Go to previous messageGo to next message
BlackSwan
Messages: 25046
Registered: January 2009
Location: SoCal
Senior Member
It invokes the OO constructor.
Re: NEW Keyword [message #225675 is a reply to message #225070] Tue, 20 March 2007 21:28 Go to previous message
sireeshraju
Messages: 32
Registered: October 2005
Member

Hi,

Even if i don't use that NEW Keyword also it works,isn't it?

Previous Topic: update the table issue
Next Topic: ORA-00902: invalid datatype
Goto Forum:
  


Current Time: Thu Dec 08 16:04:44 CST 2016

Total time taken to generate the page: 0.09818 seconds