Presentation is loading. Please wait.

Presentation is loading. Please wait.

Records Oracle Database PL/SQL 10g Programming Chapter 5.

Similar presentations


Presentation on theme: "Records Oracle Database PL/SQL 10g Programming Chapter 5."— Presentation transcript:

1 Records Oracle Database PL/SQL 10g Programming Chapter 5

2 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 2 Records Implicit PL/SQL Records Implicit PL/SQL Records Explicit PL/SQL Records Explicit PL/SQL Records Explicit Compound PL/SQL Records Explicit Compound PL/SQL Records Explicit SQL Object Types Explicit SQL Object Types Explicit Compound SQL Object Types Explicit Compound SQL Object Types

3 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 3 Records Implicit PL/SQL Records Pros: Pros: Implicit records are defined by using the %ROWTYPE attribute. Implicit records are defined by using the %ROWTYPE attribute. Implicit records implement a catalog definition for a table or view. Implicit records implement a catalog definition for a table or view. Cons: Cons: Implicit record types cannot be elements of compound records. Implicit record types cannot be elements of compound records. Implicit records cannot be used as formal parameters in the header of program units. Implicit records cannot be used as formal parameters in the header of program units. Implicit record types cannot be used as return data types for functions. Implicit record types cannot be used as return data types for functions.

4 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 4 Records Implicit PL/SQL Records DECLARE row a_table%ROWTYPE; row a_table%ROWTYPE;BEGIN row.id := 1; row.id := 1; row.name := 'Ian'; row.name := 'Ian'; INSERT INTO a_table INSERT INTO a_table VALUES VALUES (row.id, row.name); (row.id, row.name); COMMIT; COMMIT;END;/

5 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 5 Records Explicit PL/SQL Records Pros: Pros: Explicit records are defined by using defining a PL/SQL data type. Explicit records are defined by using defining a PL/SQL data type. Explicit records implement a qualified structure that can map to: Explicit records implement a qualified structure that can map to: A catalog definition for a table or view. A catalog definition for a table or view. A non-catalog definition. A non-catalog definition. Explicit records can be elements of compound record structures. Explicit records can be elements of compound record structures. Explicit records can be used as formal parameters in the header of program units. Explicit records can be used as formal parameters in the header of program units. Explicit records can be used as return data types for functions, provided they are not used in SQL statements. Explicit records can be used as return data types for functions, provided they are not used in SQL statements. Cons: Cons: Explicit record type require formal structure definition. Explicit record type require formal structure definition.

6 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 6 Records Explicit PL/SQL Records DECLARE TYPE row_record IS RECORD TYPE row_record IS RECORD (id INTEGER (id INTEGER,name VARCHAR2(10));,name VARCHAR2(10)); row ROW_RECORD; row ROW_RECORD;BEGIN row.id := 1; row.id := 1; row.name := 'Ian'; row.name := 'Ian'; INSERT INTO a_table INSERT INTO a_table VALUES VALUES (row.id, row.name); (row.id, row.name); COMMIT; COMMIT;END;/

7 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 7 Records Explicit Compound PL/SQL Records Pros: Pros: Explicit compound records are defined by using layered definitions of PL/SQL data types in a compound data type. Explicit compound records are defined by using layered definitions of PL/SQL data types in a compound data type. Explicit compound records implement a qualified structure that can map to: Explicit compound records implement a qualified structure that can map to: A catalog definition for a table or view. A catalog definition for a table or view. A non-catalog definition. A non-catalog definition. Explicit compound records can be elements of larger compound record structures. Explicit compound records can be elements of larger compound record structures. Explicit records can be used as formal parameters in the header of program units. Explicit records can be used as formal parameters in the header of program units. Explicit records can be used as return data types for functions, provided they are not used in SQL statements. Explicit records can be used as return data types for functions, provided they are not used in SQL statements. Cons: Cons: Explicit record type require formal layered structure definition. Explicit record type require formal layered structure definition.

8 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 8 Records Explicit Compound PL/SQL Records DECLARE TYPE i_record IS RECORD TYPE i_record IS RECORD (individual_id INTEGER (individual_id INTEGER,individual_name VARCHAR2(20));,individual_name VARCHAR2(20)); TYPE a_record IS RECORD TYPE a_record IS RECORD (address_id INTEGER (address_id INTEGER,address VARCHAR2(30));,address VARCHAR2(30)); TYPE pda_entry IS RECORD TYPE pda_entry IS RECORD (person I_RECORD (person I_RECORD,place A_RECORD);,place A_RECORD); row PAD_ENTRY; row PAD_ENTRY;BEGIN … next_slide … … next_slide …END;/

9 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 9 Records Explicit Compound PL/SQL Records DECLARE … prior_slide … … prior_slide …BEGIN pda_entry.i_record.individual_id := 1; pda_entry.i_record.individual_id := 1; pda_entry.i_record.individual_name := 'Ian';; pda_entry.i_record.individual_name := 'Ian';; pda_entry.a_record.address_id := 1; pda_entry.a_record.address_id := 1; pda_entry.a_record.address := '11 Main, Tracy, CA'; pda_entry.a_record.address := '11 Main, Tracy, CA';END;/

10 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 10 Records Explicit SQL Object Types Pros: Pros: Explicit objects are defined as SQL data types, with specifications and bodies. Explicit objects are defined as SQL data types, with specifications and bodies. Explicit objects can be used as data types in tables and views. Explicit objects can be used as data types in tables and views. Explicit objects can be elements of larger objects. Explicit objects can be elements of larger objects. Explicit objects can be used as formal parameters in the header of program units. Explicit objects can be used as formal parameters in the header of program units. Explicit objects can be used as return data types for functions, and they work in SQL statements too. Explicit objects can be used as return data types for functions, and they work in SQL statements too. Cons: Cons: Explicit objects require explicit construction. Explicit objects require explicit construction. Explicit objects are not interchangeable with explicit records. Explicit objects are not interchangeable with explicit records.

11 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 11 Records Explicit SQL Object Type Specification CREATE [OR REPLACE] TYPE i_object AS OBJECT (individual_id INTEGER,individual_name VARCHAR2(20),CONSTRUCTOR FUNCTION i_object (individual_id INTEGER,individual_name VARCHAR2) RETURN SELF AS RESULT) INSTANTIABLE NOT FINAL; /

12 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 12 Records Explicit SQL Object Type Body CREATE [OR REPLACE] TYPE i_object AS CONSTRUCTOR FUNCTION i_object (individual_id INTEGER,individual_name VARCHAR2) RETURN SELF AS RESULT IS BEGIN BEGIN self.individual_id := individual_id; self.individual_id := individual_id; self.individual_name := individual_name; self.individual_name := individual_name; RETURN; RETURN; END; END;END;/

13 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 13 Records Explicit SQL Object Type Implementation DECLARE i_object_instance I_OBJECT; i_object_instance I_OBJECT;BEGIN i_instance := i_object( 1, 'Ian'); i_instance := i_object( 1, 'Ian'); INSERT INTO a_table INSERT INTO a_table VALUES VALUES (i_instance.id (i_instance.id,i_instance.name);,i_instance.name); COMMIT; COMMIT;END;/

14 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 14 Records Explicit Compound SQL Object Types Pros: Pros: Explicit compound object types are defined as SQL data types, with specifications and bodies dependent on other object types. Explicit compound object types are defined as SQL data types, with specifications and bodies dependent on other object types. Explicit objects can be used as data types in tables and views. Explicit objects can be used as data types in tables and views. Explicit objects can be elements of larger objects. Explicit objects can be elements of larger objects. Explicit objects can be used as formal parameters in the header of program units. Explicit objects can be used as formal parameters in the header of program units. Explicit objects can be used as return data types for functions, and they work in SQL statements too. Explicit objects can be used as return data types for functions, and they work in SQL statements too. Cons: Cons: Explicit objects require explicit construction. Explicit objects require explicit construction. Explicit objects are not interchangeable with explicit records. Explicit objects are not interchangeable with explicit records.

15 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 15 Records Explicit Compound SQL Object Type Specification CREATE [OR REPLACE] TYPE i_compound_object AS OBJECT (individual I_OBJECT,address I_ADDRESS,CONSTRUCTOR FUNCTION i_compound_object (individual I_OBJECT,address I_ADDRESS) RETURN SELF AS RESULT) INSTANTIABLE NOT FINAL; /

16 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 16 Records Explicit Compound SQL Object Type Body CREATE [OR REPLACE] TYPE i_compound_object AS CONSTRUCTOR FUNCTION i_compound_object (individual I_OBJECT,address I_ADDRESS) RETURN SELF AS RESULT IS BEGIN BEGIN self.individual := individual; self.individual := individual; self.address := address; self.address := address; RETURN; RETURN; END; END;END;/

17 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 17 Records Explicit Compound SQL Object Type Body DECLARE i_object_instance I_COMPOUND_OBJECT; i_object_instance I_COMPOUND_OBJECT;BEGIN i_instance := i_compound_object( i_instance := i_compound_object( i_object( 1, 'Ian'); i_object( 1, 'Ian'); i_address('11 Main, Tracy, CA')); i_address('11 Main, Tracy, CA')); INSERT INTO individual VALUES INSERT INTO individual VALUES (i_object.individual.id (i_object.individual.id,i_object.individual_name);,i_object.individual_name); … other_table_insert … … other_table_insert …END;/

18 2006 Oracle Database PL/SQL 10g Programming (Chapter 5)Page 18 Summary Implicit PL/SQL Records Implicit PL/SQL Records Explicit PL/SQL Records Explicit PL/SQL Records Explicit Compound PL/SQL Records Explicit Compound PL/SQL Records Explicit SQL Object Types Explicit SQL Object Types Explicit Compound SQL Object Types Explicit Compound SQL Object Types


Download ppt "Records Oracle Database PL/SQL 10g Programming Chapter 5."

Similar presentations


Ads by Google