Objects

Create class

CREATE TYPE className AS OBJECT (
attributeName INT,
attName VARCHAR(20),
MEMBER FUNCTION funcName RETURN INTEGER)
NOT FINAL; # can have children
/

Define function

CREATE TYPE BODY className AS 
	MEMBER FUNCTION funcName RETURN INTEGER IS
		# DEFINE VARS	
		BEGIN
			# CODE
			RETURN val;
	END funcName;
END;
/

Overriding a function

# overrides the function in the subType
# baseType maintains its oringal method

create type employeeType under PersonType (
    roleStartDate date,
    member function durationInRole return integer,
		overrinding member function getAge return integer
)
FINAL;
/


create or replace type body employeeType as 
overriding member function getAge return integer is
	# varss
        begin
						# code
        end durationInRole;
    end;
/

Calling function

SELECT n.colName.funcName() FROM tableName n;

Treat

SELECT n.colName.attributeName FROM tableName n;

# since the datatype must be the baseType
# you cannot access attributes from the sub type
# this fixes that issue
SELECT TREAT(n.colName AS subType).attributeName FROM tableName n;

Putting it in a Table

CREATE TABLE tableName (
	colName className, # class name needs to be the base-type
	#... other attributes
);

Inserting data

NOTE: child of the class, is put in-place of className

INSERT INTO tableName VALUES (
	className(val1, val2), # constructor
	22 # other values...
);

# inserting a object refrence
# NOTE className has 1 attribute, this is the refrence
INSERT INTO tableName VALUES (
	className((SELECT n.objectType From tableName n WHERE...)));

Drop

DROP TYPE className FORCE; 
# force will drop it even if it is in the defininion of other types

DROP TYPE BODY className;
# drops all functions -  i think

Alter

ALTER TYPE className ADD ATTRIBUTE (attributeName INT) CASCADE;
#                                                      ^^^^^^^ 
#                                    Change will be passed down to children

ALTER TYPE className DROP ATTRIBUTE (attributeName INT) CASCADE;

ALTER TYPE className NOT FINAL CASCADE CONVERT TO SUBSTITUTABLE;
# will change to NOT FINAL

Reference to other objects

CREATE TYPE className AS OBJECT (
	referenceName REF otherClassName);
/

Inheritance

CREATE TYPE subTypeName UNDER baseType (
	attribute1 INT,
	attribute2 INT)
FINAL;
/