Waiting for answer This question has not been answered yet. You can hire a professional tutor to get the answer.

QUESTION

Consider the following SQL statements:

Consider the following SQL statements:

CREATE TYPE PointType AS OBJECT (

x NUMBER,

y NUMBER);

/

CREATE TYPE LineType AS OBJECT ( end1

PointType,

end2 PointType,

MAP MEMBER FUNCTION something1 RETURN NUMBER);

/

CREATE OR REPLACE TYPE BODY LineType AS

MAP MEMBER FUNCTION something1 RETURN NUMBER IS BEGIN

RETURN SQRT((end1.x-end2.x)*(end1.x-end2.x) + (end1.y-

end2.y)*(end1.y-end2.y));

END;

END;

/

CREATE TABLE Lines of LineType;

INSERT INTO Lines

VALUES( LineType( PointType(3.0, 3.0), PointType(6.0, 7.0) ) ); INSERT

INTO Lines

VALUES( LineType( PointType(0.0, 0.0), PointType(1.5, 2.0) ) ); INSERT

INTO Lines

VALUES( LineType( PointType(0.0, 0.0), PointType(6.0, 8.0) ) );

a) What does the member function "something1" do?

b) What would be the result after running the following query? SELECT

* FROM lines L

ORDER BY VALUE(L);

Now, assume that we change our type definitions to:

CREATE TYPE PointType AS OBJECT (

x NUMBER,

y NUMBER);

/

CREATE TYPE LineType AS OBJECT (

end1 PointType,

end2 PointType,

ORDER MEMBER FUNCTION something2(line lineType)

RETURN INTEGER);

/

CREATE OR REPLACE TYPE BODY LineType AS

ORDER MEMBER FUNCTION something2(line lineType) RETURN INTEGER

IS

BEGIN

IF SQRT((end1.x-end2.x)*(end1.x-end2.x) +

(end1.y-end2.y)*(end1.y-end2.y)) >

SQRT((line.end1.x-line.end2.x)*(line.end1.x-line.end2.x) +

(line.end1.y-line.end2.y)*(line.end1.y-line.end2.y)) THEN

RETURN 1;

ELSIF SQRT((end1.x-end2.x)*(end1.x-end2.x) + (end1.y-

end2.y)*(end1.y-end2.y)) < SQRT((line.end1.x-

line.end2.x)*(line.end1.x-line.end2.x) + (line.end1.y-

line.end2.y)*(line.end1.y-line.end2.y)) THEN

RETURN -1;

ELSE RETURN 0;

END IF;

END;

END;

/

CREATE TABLE Lines of LineType;

INSERT INTO Lines

VALUES( LineType( PointType(0.0, 0.0), PointType(3.0, 4.0) ) ); INSERT

INTO Lines

VALUES( LineType( PointType(3.0, 3.0), PointType(4.0, 5.0) ) ); INSERT

INTO Lines

VALUES( LineType( PointType(0.0, 0.0), PointType(1.0, 1.0) ) ); INSERT

INTO Lines

VALUES( LineType( PointType(0.0, 0.0), PointType(6.0, 8.0) ) );

c) What would be the result after running the following query?

SELECT *

FROM lines L

WHERE VALUE(L) = (LineType(PointType(3.0,4.0),PointType(4.0, 6.0)));

d) What would be the result after running the following query?

SELECT MAX(VALUE(L))

FROM lines L;

Show more
LEARN MORE EFFECTIVELY AND GET BETTER GRADES!
Ask a Question