Presentation is loading. Please wait.

Presentation is loading. Please wait.

Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9.

Similar presentations


Presentation on theme: "Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9."— Presentation transcript:

1 Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9

2 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 2 Using Procedures & Functions Data Dictionary Data Dictionary Subprograms Subprograms Definer Rights Definer Rights Invoker Rights Invoker Rights Purity Levels Purity Levels Multiple-Valued Functions Multiple-Valued Functions Shared Pool Shared Pool

3 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 3 Using Procedures & Functions Data Dictionary: Locations Stored Program Catalog Views: Stored Program Catalog Views: Definition views: Definition views: Stored Program Source – Stored Program Source –USER_SOURCE Stored Program Information – Stored Program Information –USER_PROCEDURES Stored Program Header – Stored Program Header –USER_ARGUMENTS Stored Program Settings – Stored Program Settings –USER_PLSQL_OBJECT_SETTINGS Dependency view: Dependency view:USER_DEPENDENCIES

4 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 4 Using Procedures & Functions Data Dictionary: Locations Object Catalog Views: Object Catalog Views: Object definitions: Object definitions:USER_SOURCE Table definitions: Table definitions: Table Structure – Table Structure –USER_TABLES Table Columns – Table Columns –USER_TAB_COLS Trigger definitions: Trigger definitions: Trigger Structure – Trigger Structure –USER_TRIGGERS Trigger Columns – Trigger Columns –USER_TRIGGER_COLS

5 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 5 Using Procedures & Functions Data Dictionary: Query Status SQL> SELECT object_name 2, object_type 2, object_type 3, status 3, status 4 FROM user_objects; 4 FROM user_objects;

6 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 6 Using Procedures & Functions Data Dictionary: Query Tables SQL> SELECT table_name 2, column_id 2, column_id 3, column_name 3, column_name 4, data_type 4, data_type 5 FROM user_tab_cols 5 FROM user_tab_cols 6 ORDER BY table_name 6 ORDER BY table_name 7, column_id; 7, column_id;

7 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 7 Using Procedures & Functions Data Dictionary: Query Programs SQL> SELECT line 2, text 2, text 3 FROM user_source 3 FROM user_source 4 WHERE name = UPPER('program_name‘); 4 WHERE name = UPPER('program_name‘);

8 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 8 Using Procedures & Functions Package Specification Subprograms: Rules Stored Package Specification Programs: Stored Package Specification Programs: Are stored in compiled p-code, like Java byte code. Are stored in compiled p-code, like Java byte code. Can be called by any other block. Can be called by any other block. Are modularized into smaller program units. Are modularized into smaller program units. Compiled p-code can be pinned in the SGA for faster execution. Compiled p-code can be pinned in the SGA for faster execution. Can be overloaded. Can be overloaded.

9 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 9 Using Procedures & Functions Package Subprograms: Stored Package stored subprograms: Package stored subprograms: Are defined as procedures in the package specification. Are defined as procedures in the package specification. Are defined as functions in the package specification. Are defined as functions in the package specification. Can use schema defined types from the package specification. Can use schema defined types from the package specification. Can use schema defined SQL types. Can use schema defined SQL types. Can use locally defined types from package body ONLY in their internal implementation: Can use locally defined types from package body ONLY in their internal implementation: Locally defined types can declared in local subprogram as variables. Locally defined types can declared in local subprogram as variables. Locally defined types cannot be used as parameter data types. Locally defined types cannot be used as parameter data types. Locally defined types cannot be used as function return data types. Locally defined types cannot be used as function return data types. Can be called from any schema PL/SQL program. Can be called from any schema PL/SQL program. Stored functions CANNOT be called from SQL when they return a PL/SQL data type. Stored functions CANNOT be called from SQL when they return a PL/SQL data type.

10 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 10 Using Procedures & Functions Package Subprograms: Stored Package stored subprogram referencing: Package stored subprogram referencing: Do not require forward referencing: Do not require forward referencing: The specification publishes their definitions. The specification publishes their definitions. The body relies on the specification to avoid forward referencing issues. The body relies on the specification to avoid forward referencing issues. Package stored subprogram overloading: Package stored subprogram overloading: Signature rules: Signature rules: The list of formal parameters must differ by either: The list of formal parameters must differ by either: The position and type of formal parameters. The position and type of formal parameters. The number of formal parameters. The number of formal parameters. The function signature may change based on the return data type. The function signature may change based on the return data type.

11 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 11 Using Procedures & Functions Package Body (Local) Subprograms: Rules Local Package Body Programs: Local Package Body Programs: Are stored in compiled p-code, like Java byte code. Are stored in compiled p-code, like Java byte code. Can be called ONLY by package blocks. Can be called ONLY by package blocks. Tightly coupled design. Tightly coupled design. Compiled p-code cannot be pinned in the SGA. Compiled p-code cannot be pinned in the SGA. Can be overloaded only within the same block. Can be overloaded only within the same block.

12 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 12 Using Procedures & Functions Package Subprograms: Local Package local subprograms: Package local subprograms: Are defined as procedures in the package body. Are defined as procedures in the package body. Are defined as functions in the package body. Are defined as functions in the package body. Can use locally defined types from the package body. Can use locally defined types from the package body. Can use schema defined types from package specifications. Can use schema defined types from package specifications. Can use schema defined SQL types. Can use schema defined SQL types. Can ONLY be called from a package body program unit. Can ONLY be called from a package body program unit. Package local subprogram referencing: Package local subprogram referencing: Require forward referencing, like anonymous block subprograms. Require forward referencing, like anonymous block subprograms. Package local subprogram overloading: Package local subprogram overloading: Follows the same rules as stored subprograms. Follows the same rules as stored subprograms.

13 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 13 Using Procedures & Functions Package Subprograms: Dependencies Timestamp Model (default): Timestamp Model (default): Checks to make sure that dependents have an early compilation timestamp. Checks to make sure that dependents have an early compilation timestamp. Cannot resolve distributed timestamps in different timezones. Cannot resolve distributed timestamps in different timezones. Signature Model: Signature Model: Checks to make sure that the signature for functions and procedures do not change between compilations. Checks to make sure that the signature for functions and procedures do not change between compilations. Works in distributed configurations without impacts of region timezones. Works in distributed configurations without impacts of region timezones.

14 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 14 Using Procedures & Functions Package Subprograms: Serially Reusable Non-Serially Reusable (default): Non-Serially Reusable (default): Runtime state is kept in process memory between calls during a session. Runtime state is kept in process memory between calls during a session. Requires memory in the SGA for all logged-on users. Requires memory in the SGA for all logged-on users. Serially Reusable: Serially Reusable: Runtime state is refreshed after each database call. Runtime state is refreshed after each database call. Requires memory in the SGA for users concurrently calling the same program. Requires memory in the SGA for users concurrently calling the same program.

15 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 15 Using Procedures & Functions Definer Rights: Description Definer rights Definer rights Is the default when creating stored programs. Is the default when creating stored programs. Means that the stored program executes with the same privileges as the defining user. Means that the stored program executes with the same privileges as the defining user. Can mean that calling the stored programs lets it run against any schema level data. Can mean that calling the stored programs lets it run against any schema level data. Typically means that users only access a slice of data in any schema, like a private virtual database. Typically means that users only access a slice of data in any schema, like a private virtual database.

16 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 16 Using Procedures & Functions Definer Rights: Depiction

17 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 17 Using Procedures & Functions Invoker Rights: Description Invoker rights Invoker rights Is the override when creating stored programs. Is the override when creating stored programs. Means that the stored program executes with the local privileges, which generally differ from the definer’s privileges. Means that the stored program executes with the local privileges, which generally differ from the definer’s privileges. Typically means that users only access their own schema data, like a distributed or local database. Typically means that users only access their own schema data, like a distributed or local database.

18 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 18 Using Procedures & Functions Invoker Rights: Depiction

19 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 19 Using Procedures & Functions Purity Level: Defined Purity levels restrict the behavior of stored programs. Purity levels restrict the behavior of stored programs. Purity level guarantees are optional beginning with Oracle 8i. Purity level guarantees are optional beginning with Oracle 8i. Purity levels are: Purity levels are: Writes no database states (WNDS), which disallows DML statements, like INSERT, UPDATE and DELETE. Writes no database states (WNDS), which disallows DML statements, like INSERT, UPDATE and DELETE. Reads no database states (RNDS), which disallows DQL statements, like SELECT. Reads no database states (RNDS), which disallows DQL statements, like SELECT. Writes no package states (WNPS), which disallows changes to package variables by assignment operations (including the FETCH cursor INTO variable syntax). Writes no package states (WNPS), which disallows changes to package variables by assignment operations (including the FETCH cursor INTO variable syntax). Reads no package states (RNPS), which disallows assigning any package variable values. Reads no package states (RNPS), which disallows assigning any package variable values.

20 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 20 Using Procedures & Functions Multiple-Valued Functions: Defined A multiple-valued function exists when the return type of a stored or local function returns a system reference cursor, or a user-defined data type that has multiple rows.

21 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 21 Using Procedures & Functions Multiple-Valued Functions: Rules A multiple-valued functions must return the value to the same type variable, which is done by: A multiple-valued functions must return the value to the same type variable, which is done by: Assignment in a calling PL/SQL block. Assignment in a calling PL/SQL block. Assignment to a bind variable using a system reference cursor. Assignment to a bind variable using a system reference cursor. A multiple-valued function returning a PL/SQL variable can ONLY be used inside another PL/SQL block. A multiple-valued function returning a PL/SQL variable can ONLY be used inside another PL/SQL block.

22 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 22 Using Procedures & Functions Shared Pool: Pinning Pinning in the SGA shared pool can accelerate and guarantee behavior of frequently called stored programs: Pinning in the SGA shared pool can accelerate and guarantee behavior of frequently called stored programs: This places the p-code in the shared pool. This places the p-code in the shared pool. This prevents the least used algorithm from removing it inbetween calls to it. This prevents the least used algorithm from removing it inbetween calls to it. The DBMS_SHARED_POOL.KEEP enables pinning a stored program into the SGA. The DBMS_SHARED_POOL.KEEP enables pinning a stored program into the SGA. The DBMS_SHARED_POOL.UNKEEP removes a pinned stored program from the SGA. The DBMS_SHARED_POOL.UNKEEP removes a pinned stored program from the SGA.

23 2006 Oracle Database PL/SQL 10g Programming (Chapter 9)Page 23 Summary Data Dictionary Data Dictionary Subprograms Subprograms Definer Rights Definer Rights Invoker Rights Invoker Rights Purity Levels Purity Levels Multiple-Valued Functions Multiple-Valued Functions Shared Pool Shared Pool


Download ppt "Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9."

Similar presentations


Ads by Google