DROP TYPE Position;
CREATE OR REPLACE TYPE
Position AS OBJECT
(longitude NUMBER(11,7),
lattitude NUMBER(11,7),
CONSTRUCTOR FUNCTION Position(
long NUMBER,
latt NUMBER
) RETURN SELF AS RESULT
)FINAL;
/
CREATE OR REPLACE TYPE BODY Position AS
CONSTRUCTOR FUNCTION Position(
long NUMBER,
latt NUMBER
) RETURN SELF AS RESULT IS
BEGIN
SELF.longitude := long;
SELF.lattitude := latt;
RETURN;
END;
END;
/
DESC Position;
DROP TABLE District_Info;
CREATE TABLE District_Info(
Dname VARCHAR2(20),
DPos Position,
Boundary_dist VARCHAR2(20),
Launch_ghat CHAR(1)
);
DESC District_Info;
INSERT INTO District_Info (Dname,DPos,Boundary_dist,Launch_ghat)
VALUES ('d',Position(1.1, 1.1),'gr','y');
DROP TYPE Position; CREATE OR REPLACE TYPE Position AS OBJECT (longitude NUMBER(11,7), lattitude NUMBER(11,7),
Share
Your problem is that you have defined two constructors of the same type, but you didn’t realize you did probably.
When you create an object type, Oracle creates a default constructor, with parameters that match the parameters of the type. Therefore, when you also defined a constructor with only lattitude and longitude as inputs, Oracle cannot work out which constructor to call, the default created one, or your one, so it errors with:
To fix this, you can simplify your code:
Ie, you don’t need the constructor declaration or the body. If you like, you can have a DIFFERENT constructor, eg: