Presentation is loading. Please wait.

Presentation is loading. Please wait.

Demostraciones de Operaciones DML para OR. Subtipos y Herencia CREATE TYPE person_t AS OBJECT (name VARCHAR2(100), ssn NUMBER) NOT FINAL; / CREATE TYPE.

Similar presentations


Presentation on theme: "Demostraciones de Operaciones DML para OR. Subtipos y Herencia CREATE TYPE person_t AS OBJECT (name VARCHAR2(100), ssn NUMBER) NOT FINAL; / CREATE TYPE."— Presentation transcript:

1 Demostraciones de Operaciones DML para OR

2 Subtipos y Herencia CREATE TYPE person_t AS OBJECT (name VARCHAR2(100), ssn NUMBER) NOT FINAL; / CREATE TYPE employee_t UNDER person_t (department_id NUMBER, salary NUMBER) NOT FINAL; / CREATE TYPE part_time_emp_t UNDER employee_t (num_hrs NUMBER); /

3 Inserción usando subtipos En Oracle los subtipos no pueden ser solapados. insert into persons values(part_time_emp_t('Claudia Gonzalez', ,10,1000,2)); Insert into persons values(employee_t('Edna Ruckhaus', ,10,7000)); Insert into persons values(person_t('Soraya Abad', ));

4 Seleccionando SQL> select * from persons; NAME SSN Claudia Gonzalez Edna Ruckhaus Soraya Abad

5 Seleccionando SQL> select value(p) from persons p; VALUE(P)(NAME, SSN) PART_TIME_EMP_T('Claudia Gonzalez', , 10, 1000, 2) EMPLOYEE_T('Edna Ruckhaus', , 10, 7000) PERSON_T('Soraya Abad', )

6 Evitando subtipos SELECT VALUE(p) FROM persons p WHERE VALUE(p) IS OF (ONLY employee_t ); VALUE(P)(NAME, SSN) EMPLOYEE_T('Edna Ruckhaus', , 10, 7000)

7 Varrays CREATE TYPE phones AS VARRAY(10) OF varchar2(10); / Create table suppliers( supcode number(5), Company varchar2(20), ph phones);

8 Insertando en Varrays insert into suppliers values (101,’Interface Computers’, Phones(‘ ’,’ ’)); insert into suppliers values (102,’Western Engg. Corp’, Phones(‘ ’,’ ’,’ ’));

9 Consultando SQL> select * from suppliers; SUPCODE COMPANY PH Interface Computers PHONES(' ', ' ') 102 Western Engg. Corp PHONES(' ', ' ', ' ')

10 Nested Tables CREATE TYPE people_typ AS TABLE OF person_typ; / CREATE TABLE people_tab ( group_no NUMBER, people_column people_typ ) NESTED TABLE people_column STORE AS people_column_nt;

11 Nested Tables INSERT INTO people_tab VALUES ( 100, people_typ( person_typ(1, 'John Smith', ' '), person_typ(2, 'Diane Smith', NULL)));

12 Ref CREATE TYPE emp_person_typ AS OBJECT ( name VARCHAR2(30), manager REF emp_person_typ ); / CREATE TABLE emp_person_obj_table OF emp_person_typ;

13 Ref INSERT INTO emp_person_obj_table VALUES ( emp_person_typ ('John Smith', NULL)); INSERT INTO emp_person_obj_table SELECT emp_person_typ ('Bob Jones', REF(e)) FROM emp_person_obj_table e WHERE e.name = 'John Smith';

14 Funciones CREATE TYPE person_typ AS OBJECT ( idno NUMBER, name VARCHAR2(30), phone VARCHAR2(20), MAP MEMBER FUNCTION get_idno RETURN NUMBER, STATIC FUNCTION show_super (person_obj in person_typ) RETURN VARCHAR2, MEMBER FUNCTION show RETURN VARCHAR2) NOT FINAL; /

15 CREATE TYPE BODY person_typ AS MAP MEMBER FUNCTION get_idno RETURN NUMBER IS BEGIN RETURN idno; END; -- static function that can be called by subtypes STATIC FUNCTION show_super (person_obj in person_typ) RETURN VARCHAR2 IS BEGIN RETURN 'Id: ' || TO_CHAR(person_obj.idno) || ', Name: ' || person_obj.name; END; -- function that can be overriden by subtypes MEMBER FUNCTION show RETURN VARCHAR2 IS BEGIN RETURN person_typ.show_super ( SELF ); END; /


Download ppt "Demostraciones de Operaciones DML para OR. Subtipos y Herencia CREATE TYPE person_t AS OBJECT (name VARCHAR2(100), ssn NUMBER) NOT FINAL; / CREATE TYPE."

Similar presentations


Ads by Google