Download presentation
Presentation is loading. Please wait.
Published byEduardo Holten Modified over 9 years ago
1
Professor: Dr. Shu-Ching Chen TA: Hsin-Yu Ha
2
Objects Varray Nested Table Transaction Control Language(TCL)
3
User-Defined types Advantage: Encapsulate operations along with data Are efficient Can represent Part-Whole relationships
5
CREATE TYPE t AS OBJECT ( list of attributes and methods ); / CREATE TYPE PointType AS OBJECT ( X NUMBER, Y NUMBER ); /
6
CREATE TYPE Address_Ty AS OBJECT ( Street VARCHAR(20), City VARCHAR(20), State CHAR(2), Zip NUMBER ); CREATE TYPE Person_Ty AS OBJECT( Name VARCHAR(25), Address Address_Ty );
7
CREATE TABLE Customer( CustomerID NUMBER, Person Person_Ty ); INSERT INTO Customer VALUES (1, Person_Ty(‘Chris’, Address_Ty(…)));
8
SELECT Name FROM Customer; SELECT C.Person.Name FROM Customer C;
9
Alice: GRANT EXECUTE ON Address_Ty to Bob; Bob: CREATE TYPE Person_Ty as Object( Name VARCHAR(25), Address Alice.Address_Ty );
10
Method Are functions or procedures that you can declare in an object type definition SELECT c.contact.get_idno() FROM contacts c
11
CREATE TYPE LineType AS OBJECT( end1 PointType, end2 PointType, MEMBER FUNCTION length(scale NUMBER) RETURN NUMBER ); CREATE TYPE PointType AS OBJECT( X NUMBER, Y NUMBER, );
12
CREATE TYPE BODY LineType AS MEMBER FUNCTION lengh(scale NUMBER) RETURN NUMBER IS BEGIN RETURN scale * SQRT((SELF.end1.x – SELF.end2.x) * (SELF.end1.x – SELF.end2.x) + (SELF.end1.y – SELF.end2.y) * (SELF.end1.y – SELF.end2.y) ); END; /
13
CREATE TABLE Lines( LineID INT, Line LineType ;) INSERT INTO Lines VALUES (27, LineType( PointType (0.0, 0.0), PointType(3.0, 4.0) ) );
14
INSERT INTO Lines VALUES (27, LineType( PointType (0.0, 0.0), PointType(3.0, 4.0) ) ); SELECT lineID, ll.line.length(2.0) FROM Lines ll; lineID ll.line.length 27 10
15
DROP TYPE LineType; We must first drop the table Lines
16
ALTER Type Add and drop attributes Add and drop methods Modify a numeric attribute to increase its length, precision, or scale Modify a varying length character attribute to increase its length
17
CREATE TYPE phone_t AS OBJECT( a_code CHAR(3), p_number CHAR(8) ); ALTER TYPE phone_t ADD ATTRIBUTE (countycode CHAR(3));
18
An ordered set of data elements CREATE TYPE email_list_arr AS VARRAY(10) of VARCHAR2(80) Index Data Type
19
CREATE TABLE Borrower( Name VARCHAR(25), Book VARCHAR(25), Constraint Borrower_PK primary key (Name, Book) ); CREATE TYPE Books_VA AS Varray(5) of VARCHAR(25); Book Books_VA INSERT INTO Borrower VALUES( ‘Bob’, Books_VA(‘Books1’, ‘Books2’);
20
CREATE TYPE Book_ty AS OBJECT( BookName VARCHAR(25), ISBN NUMBER); CREATE TYPE Books_VA AS Varray(5) of Book_ty; CREATE TABLE Borrower( Name VARCHAR(25), Book Books_VA, Constraint Borrower_PK primary key (Name, Book) );
21
CREATE TYPE phone_ty AS OBJECT ( country_code VARCHAR2(2), area_code VARCHAR2(3), ph_number VARCHAR2(7) ); CREATE TYPE phone_varray_ty AS VARRAY(5) OF phone_ty; CREATE TABLE dept_phone_list ( dept_no NUMBER(5), phone_list phone_varray_ty );
22
INSERT INTO dept_phone_list VALUES ( 100, phone_varray_ty( phone_ty ('01', '650', '5061111'), phone_ty ('01', '650', '5062222'), phone_ty ('01', '650', '5062525') ) );
23
An unordered set of data elements No maximum is specified
24
CREATE TYPE project_type AS OBJECT ( name VARCHAR2(50), role VARCHAR2(20) ); CREATE TYPE project_nt AS TABLE OF project_type; CREATE TABLE emp ( empno NUMBER(5), ename VARCHAR2(30), projects project_nt );
25
INSERT INTO emp VALUES(1,'Ellison', projecttable ( project_type('Telephone Billing','System Analyst'), project_type('Housing Loans','Oracle DBA') )
26
CREATE TYPE Animal_ty AS OBJECT ( Breed VARCHAR2(50), Name VARCHAR2(25), BirthDate date ); CREATE TYPE Animal_nt AS TABLE OF Animal_ty ; CREATE TABLE Breeder( BreederName VARCHAR2(25), Animals Animal_nt );
27
Transactioon A set of SQL statements Available TCL statements COMMIT ROLLBACK SAVEPOINT
28
COMMIT ROLLBACK INSERT INTO emp (empno, ename, sal) VALUES(101,’Abid’,2300) COMMIT; DELETE FROM emp; ROLLBACK;
29
insert into tom1 values( '1' ); insert into tom1 values( '2' ); insert into tom1 values( '3' ); insert into tom1 values( ‘4' ); insert into tom1 values( ‘5' ); insert into tom1 values( ‘6' ); insert into tom1 values( ‘7' ); insert into tom1 values( ‘8' ); insert into tom1 values( ‘9' ); SAVEPOINT a; ROLLBACK; COMMIT; RESULT: 7,8,9 ROLLBACK to SAVEPOINT a; RESULT: 1,2,3,7,8,9 COMMIT; ROLLBACK; RESULT: 1,2,3,4,5,6,7,8,9
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.