* Your assessment is very important for improving the workof artificial intelligence, which forms the content of this project
Download Introduction to Databases
Microsoft Access wikipedia , lookup
Extensible Storage Engine wikipedia , lookup
Entity–attribute–value model wikipedia , lookup
Concurrency control wikipedia , lookup
Ingres (database) wikipedia , lookup
Microsoft Jet Database Engine wikipedia , lookup
Clusterpoint wikipedia , lookup
Microsoft SQL Server wikipedia , lookup
Database model wikipedia , lookup
Oracle Database wikipedia , lookup
Open Database Connectivity wikipedia , lookup
Using Procedures & Functions Oracle Database PL/SQL 10g Programming Chapter 9 Using Procedures & Functions 2006 Data Dictionary Subprograms Definer Rights Invoker Rights Purity Levels Multiple-Valued Functions Shared Pool Oracle Database PL/SQL 10g Programming (Chapter 9) Page 2 Using Procedures & Functions Data Dictionary: Locations Stored Program Catalog Views: Definition views: Stored Program Source – USER_SOURCE Stored Program Information – USER_PROCEDURES Stored Program Header – USER_ARGUMENTS Stored Program Settings – USER_PLSQL_OBJECT_SETTINGS Dependency view: USER_DEPENDENCIES 2006 Oracle Database PL/SQL 10g Programming (Chapter 9) Page 3 Using Procedures & Functions Data Dictionary: Locations Object Catalog Views: Object definitions: USER_SOURCE Table definitions: Table Structure – USER_TABLES USER_TAB_COLS Trigger definitions: 2006 Table Columns – Trigger Structure – USER_TRIGGERS Trigger Columns – USER_TRIGGER_COLS Oracle Database PL/SQL 10g Programming (Chapter 9) Page 4 Using Procedures & Functions Data Dictionary: Query Status SQL> 2 3 4 2006 SELECT , , FROM object_name object_type status user_objects; Oracle Database PL/SQL 10g Programming (Chapter 9) Page 5 Using Procedures & Functions Data Dictionary: Query Tables SQL> 2 3 4 5 6 7 2006 SELECT , , , FROM ORDER BY , table_name column_id column_name data_type user_tab_cols table_name column_id; Oracle Database PL/SQL 10g Programming (Chapter 9) Page 6 Using Procedures & Functions Data Dictionary: Query Programs SQL> 2 3 4 2006 SELECT , FROM WHERE line text user_source name = UPPER('program_name‘); Oracle Database PL/SQL 10g Programming (Chapter 9) Page 7 Using Procedures & Functions Package Specification Subprograms: Rules Stored Package Specification Programs: 2006 Are stored in compiled p-code, like Java byte code. Can be called by any other block. Are modularized into smaller program units. Compiled p-code can be pinned in the SGA for faster execution. Can be overloaded. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 8 Using Procedures & Functions Package Subprograms: Stored Package stored subprograms: Are defined as procedures 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 SQL types. Can use locally defined types from package body ONLY in their internal implementation: 2006 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 function return data types. Can be called from any schema PL/SQL program. Stored functions CANNOT be called from SQL when they return a PL/SQL data type. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 9 Using Procedures & Functions Package Subprograms: Stored Package stored subprogram referencing: Do not require forward referencing: The specification publishes their definitions. The body relies on the specification to avoid forward referencing issues. Package stored subprogram overloading: Signature rules: The list of formal parameters must differ by either: 2006 The position and type of formal parameters. The number of formal parameters. The function signature may change based on the return data type. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 10 Using Procedures & Functions Package Body (Local) Subprograms: Rules Local Package Body Programs: 2006 Are stored in compiled p-code, like Java byte code. Can be called ONLY by package blocks. Tightly coupled design. Compiled p-code cannot be pinned in the SGA. Can be overloaded only within the same block. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 11 Using Procedures & Functions Package Subprograms: Local Package local subprograms: Are defined as procedures in the package body. Are defined as functions in the package body. Require forward referencing, like anonymous block subprograms. Package local subprogram overloading: 2006 Can ONLY be called from a package body program unit. Package local subprogram referencing: Can use locally defined types from the package body. Can use schema defined types from package specifications. Can use schema defined SQL types. Follows the same rules as stored subprograms. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 12 Using Procedures & Functions Package Subprograms: Dependencies Timestamp Model (default): Signature Model: 2006 Checks to make sure that dependents have an early compilation timestamp. Cannot resolve distributed timestamps in different timezones. 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. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 13 Using Procedures & Functions Package Subprograms: Serially Reusable Non-Serially Reusable (default): Serially Reusable: 2006 Runtime state is kept in process memory between calls during a session. Requires memory in the SGA for all logged-on users. Runtime state is refreshed after each database call. Requires memory in the SGA for users concurrently calling the same program. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 14 Using Procedures & Functions Definer Rights: Description Definer rights 2006 Is the default when creating stored programs. 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. Typically means that users only access a slice of data in any schema, like a private virtual database. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 15 Using Procedures & Functions Definer Rights: Depiction 2006 User #1 User #3 User #2 User #4 Oracle Database PL/SQL 10g Programming (Chapter 9) Page 16 Using Procedures & Functions Invoker Rights: Description Invoker rights 2006 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. Typically means that users only access their own schema data, like a distributed or local database. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 17 Using Procedures & Functions Invoker Rights: Depiction 2006 User #1 User #3 User #2 User #4 Oracle Database PL/SQL 10g Programming (Chapter 9) Page 18 Using Procedures & Functions Purity Level: Defined Purity levels restrict the behavior of stored programs. Purity level guarantees are optional beginning with Oracle 8i. Purity levels are: 2006 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. 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. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 19 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. 2006 Oracle Database PL/SQL 10g Programming (Chapter 9) Page 20 Using Procedures & Functions Multiple-Valued Functions: Rules A multiple-valued functions must return the value to the same type variable, which is done by: 2006 Assignment in a calling PL/SQL block. 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. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 21 Using Procedures & Functions Shared Pool: Pinning Pinning in the SGA shared pool can accelerate and guarantee behavior of frequently called stored programs: 2006 This places the p-code in the shared pool. 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.UNKEEP removes a pinned stored program from the SGA. Oracle Database PL/SQL 10g Programming (Chapter 9) Page 22 Summary 2006 Data Dictionary Subprograms Definer Rights Invoker Rights Purity Levels Multiple-Valued Functions Shared Pool Oracle Database PL/SQL 10g Programming (Chapter 9) Page 23