Oracle Plsql

August 29, 2017 | Author: Peter Makram | Category: Pl/Sql, Sql, Control Flow, Information Retrieval, Information Technology Management
Share Embed Donate


Short Description

Descripción: Oracle Plsql...

Description

ORACLE PLSQL Procedural Language Structure Query Language

Part 1 : Part 2 :

PLSQL Course PLSQL practices and problems

Prepared By : Email : Mobile No :

Oracle Complete PLSQL Reference

Ashraf Omar Hussein [email protected] +20101552319

0

Part 1 :

PLSQL Course

1. 2. 3. 4. 5. 6. 7.

Why do you need PLSQL? PLSQL Block Structure Variables Types Anonymous Block Stored Procedure Parameter Control Structure 7.1 IF Condition 7.2 Case Expression 7.3 Loop 8. Cursor 9. Handle Exception 10. DataBase Trigger 11. Function 12. Package

Oracle Complete PLSQL Reference

1

13. Q: What is PLSQL ? A: It is a procedural anguage Structure Query language Q: Why do you Need PLSQL Language ? 1

Bad peformance for the heavy network traffic

SQL

Applicat ion 1

SQL SQL

DATA BASE

SQL SQL SQL

2

Cann’t write more than one SQL command at the same Time

3

SQL commands are not depended to each other and Not executed in a specific order

4

SQL command s are not saved in the DB server

5

SQL Commands are not shared for all users

6

SQL Commands cann’t handle user Error (Exception)

7

SQL Commands are static NOT Dynamic

8

SQL Commands are executed Manually not Automatically

9

SQL Commands don’t use IF condition

10

SQL Command don’t use LOOP statement

11

SQl Command don’t use

12

SQL Command don’t use Variable

Applicat ion 2

Q: What are the benefits of PLSQL ? 1

Improve Performance and reduce network traffic between client and server by agrouping sql statements together in one block and send it to the server in one call

2

Portability: PlSQl is available on any kind of platform

3

Modularize Programs: can contain nested Blocks

4

Integration: it can be used as developer tools (in forms and reports)or as administration tools

Oracle Complete PLSQL Reference

2

Q: How does PLSQL solve the problems of the SQL commands? 1

By creating a database Block

Q: What is a datablock Block ? 1

It is a dataase structure that contain one or more SQL commands

2

Block require that all SQL Commands to be correct for the execution . if there is one SQL command is not Correct then the whole block with all SQL Commands will not be exeucted

3

If you write more than one SQL statement you must separate them by using semi comma (;)

Q: what are the block types? 1 Anonymus Bock Not stored or saved in the DB server Not shared for all users Executed only once Created and executed during run time Cann’t accept parameter Has only one type 1. Anonymus Block

2

Subprogram – Program Unit Stored or saved in the DB server Shared for all users Executed many times as user requests Created before the execution time Can Accept Parameter Has 3 types 1. Stored Procedure 2. Function 3. Package

Anonymous Block Structure

Declaration Part Optional

Body Mandatory

Exception Part Optional

Variable Oracle Complete PLSQL Reference

3

Q: What is a Variable? 1. Is a space located in the memory can be used For Impermanent storage of One an ONLY One Value 2. Variable can store value identified by the user himself OR value retrieved form the data base table Q: Why do you use a variable? 1- Temporary storage of data: 1.1 Data can be temporarily stored in one or more variables for use when validating data input and for processing later in the data flow process such as Login Window we store the user name and password For user to check for these two values if they are stored in the data base the user will be logined successfully and if they are not stored in the data base the user will not be able to login. 2. Manipulation of stored values: 2.1 Variables can be used for calculations and other data manipulations without accessing database. 2.2 store values for calculation and the result of these calculations will be displayed in the report 3- Reusability: 3.1 After they are declared, variables can be used repeatedly in an application simply by referencing them in other statements, including other declarative statements such as local variables and global variables. 4- Ease of maintenance: 4.1 declare new variable has the same data type of other variable 4.2 declare new variable has the same data type of data base column and when changing the value in the database this value will changed automatically in the variable such as create variable storing the max value in empno column to create application trigger to increment this value for the next record Q: How do you declare a variable? 1. You must declare a variable in the declaration part of the block 2. You can decalre more than one variable in the same block BUT you must 2.1 define each varibale in a separate line 2.2 end each varibale with a semi comma (;) 3. Each variable Must has [name, data type] mandatory, [null ability, default value] optional Q: what are the rules of the Variable name ? 1. Variable names are unique within the same block but variable name may be duplicated in other block 2. Length between 1-30 charater length 3. Must start with character NOT with number or special character BUT it may include numbers and special character inside the name or at the end 4. Variable name mustn’t be the same as column name within the data base 5. It is preferable to start variable name with V_ColumnName if it contain changeable value and start variable name with C_ColumnName if it contain Constant value 6. If you declare a variable contain constant value so the keyword CONSTANT must precede the data type of the variable 7. String literals must be enclosed in single quotation marks. For example , 'Hello, world'. If there is a single quotation mark in the string, use a single quotation mark twice, for example, to insert a value FISHERMAN'S DRIVE, the string would be 'FISHERMAN''S DRIVE '.

Oracle Complete PLSQL Reference

4

Q: what are the rules when you Assign a value for the Variabe ? 1. It is good code to assign value for the variable because if you did not assign value then null will be inserted 2. To assign value for the variable you can use := or use DEFAULT as keyword 3. Variable value can be constant value or default value or expression 4. Assigning string value must be enclosed between single quotes But numeric value does not require single quotes 5. If you assign value for the variable in the declaration section and assign new value for the variable in the execution section the new value will replace the old value in the declaration part Q: What are the data types for the variables 1. Char(n) 2. Varcahr2(n) 3. Number(n) 4. Number(m,n) 5. Date 6. Binary_integer 7. Boolean 8. Long 9. Long raw

Oracle Complete PLSQL Reference

5

Examples for decalring variables 1. Use user defined datatype Declare v_job v_location v_deptno v_total_sal v_mgr c_comm v_hire_date v_orderdate c_tax_rate v_valid

varchar2(20) varchar2(50) number(5) number(9,2) number(6) CONSTANT number(5) date date CONSTANT numebr(5,2) BOOLEAN

null null not null null

not null

; := 'cairo'; := 10 := 0; DEFAULT 100; DEFAULT 1400; := TO_CHAR('1998/08/16', 'yyyy/mm/dd'); := SYSDATE + 3; := 0.15; := TRUE;

2. Use TabeName.ColumnName%type Declare v_job emp.job%type ; v_location dept.dname%type := 'cairo' ; v_deptno dept.deptno%type not null := 10; v_total_sal emp.sal%type := 0; v_mgr emp.mgr%type DEFAULT 100; c_comm CONSTANT emp.comm%type := 1400; v_hire_date emp.hiredate%type := TO_CHAR('1998/08/16', 'yyyy/mm/dd'); 3. Use Variable%type Declare v_job emp.job%type ; v_location v_job%type := 'cairo' ; v_deptno dept.deptno%type not null := 10; v_total_sal v_deptno%type := 0; v_mgr v_deptno%type DEFAULT 100; c_comm CONSTANT emp.comm%type := 1400; v_hire_date emp.hiredate%type := TO_CHAR('1998/08/16', 'yyyy/mm/dd'); 4. Use TableName%rowtype 4.1 Decalre only one variable that store the value for all row in the table 4.2 you can print the whole row value or print a specific values only Declare Emp_Row Emp%RowType; begin DBMS_OUTPUT.PUT_LINE (Emp_Row.Empno); DBMS_OUTPUT.PUT_LINE (Emp_Row.Ename); DBMS_OUTPUT.PUT_LINE (Emp_Row.Salary); End;

Oracle Complete PLSQL Reference

6

5. Use recod data type 5.1 create an object of record data type 5.2 create a variable based on that object type Declare TYPE emp_record_type IS RECORD (employee_id NUMBER(6) NOT NULL := 100, last_name employees.last_name%TYPE, job_id employees.job_id%TYPE); emp_record emp_record_type; 6. use table data type Declare Type Emp_Table is Table of EMP%RowType Index by binary integer; V_Emp Emp_table; DBMS_OUTPUT.PUT_LINE: 1. PRINT command. is DBMS_OUTPUT.PUT_LINE. DBMS_OUTPUT is Oracle-supplied package, and PUT_LINE is a procedure within that package. 2. Within a PL/SQL block, reference DBMS_OUTPUT.PUT_LINE and, in parentheses, specify the string that you want to print to the screen. The package must first be enabled in your SQL*Plus session. To do this, execute the SQL*Plus SQL> SET SERVEROUTPUT ON command.

Oracle Complete PLSQL Reference

7

Anonymus Block Best Practices 1. How to write Insert Statement without Variables

2. How to write Insert Statement with Variables

Oracle Complete PLSQL Reference

8

3. How to write Update Statement without Variables

4. How to write Update Statement with Variables

Oracle Complete PLSQL Reference

9

5. How to write Delete Statement without Variables It is not possible to write the select statement without variables because varaibles are MANDATORY in this case . Because the syntax for the SELECT statement is differe from the normal SELECT stamtent written by SQL SELECT using SQL Syntac Select From table name Where Group by Having Order by Variables are decalred imlicitly by oracle Values are printed implicitly by oralce

Oracle Complete PLSQL Reference

SELECT using PLSQL syntax Select INTO variabls ------- New From table name Where Group by Having Order by Variables are decalred Explicitly by Developer Values are printed Explicitly by Developer

10

6. How to write Update Statement with Variables You must declare variables with the same number of the columns that you retrieve in your select statement 1. Decalre variables for each column you retrive in select statement 2. Select column into variable 3. Print value for the variable by using DBMS_OUTPUT.PUT_LINE 4. you must enable DBMS_OUTPUT.PUT_LINE first by running command 5. SQL> set serveroutput on ; 6. DBMS_OUTPUT.PUT_LINE is used to pring value for one variable only . 7. If you print values for more that one variable then you can use Concat function or write DBMS_OUTPUT.PUT_LINE more than one time for each varaible you want to pring

Oracle Complete PLSQL Reference

11

Oracle Complete PLSQL Reference

12

7. How to write more that DML transactions within the anonymus block

Oracle Complete PLSQL Reference

13

8. How to write more that DML transactions within the anonymus block

Oracle Complete PLSQL Reference

14

9. Using Subsutitution Variable By using wild card &

Oracle Complete PLSQL Reference

15

9.1 Using Subsutitution Variable By using wild card &

9.2 Using Subsutitution Variable By using wild card &

Oracle Complete PLSQL Reference

16

9.3 Using Subsutitution Variable By using wild card &

Oracle Complete PLSQL Reference

17

10 . Using ROW%TYPE as a datatype 1. it can be used when you retrieve all cloumns from the table 2. you can print all the values or just a specific values only

Oracle Complete PLSQL Reference

18

11 . Using RECORD%TYPE as a datatype

Oracle Complete PLSQL Reference

19

Subprogram = Program Unit 1. Stored Procedure Parameters are optional not mandatory

Declaration Part Optional Body Mandatory Declaration Part Optional

1. all Stored procedures created are stored in user_objects 2. source code is stored in user_source

Oracle Complete PLSQL Reference

20

1.1 procedure without parameters

Oracle Complete PLSQL Reference

21

1.1 procedure without parameters

1.1 procedure without parameters Oracle Complete PLSQL Reference

22

1.1 procedure without parameters

Oracle Complete PLSQL Reference

23

1.1 procedure without parameters using TABLENAME%ROWTYPE as a datatype Using ROW%TYPE as a datatype 1. it can be used when you retrieve all cloumns from the table 2. you can print all the values or just a specific values only

Oracle Complete PLSQL Reference

24

1.1 procedure without parameters using TABLENAME%ROWTYPE as a datatype Using ROW%TYPE as a datatype

Oracle Complete PLSQL Reference

25

1.1 procedure without parameters using RECORD DATATYPE as a datatype Using RECORD DATATYPE as a datatype

Oracle Complete PLSQL Reference

26

1.2 procedure with parameters Parameter type are 1. IN Parameter ---- Default type 2. OUT Parameter 3. IN OUT Parameter You can define more that one parameters in the same procedure All parameters are defined after the procedure name

Oracle Complete PLSQL Reference

27

1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

28

1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

29

1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

30

1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

31

1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

32

1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

33

1.2 procedure with parameters -- IN parameter 1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

34

1.2 procedure with parameters -- IN parameter

Oracle Complete PLSQL Reference

35

1.2 procedure with parameters -- IN Parameter using TABLENAME%ROWTYPE as a datatype

Oracle Complete PLSQL Reference

36

1.2 procedure with parameters -- IN Parameter using TABLENAME%ROWTYPE as a datatype

1.2 procedure with parameters -- IN Parameter using RECORD DATATYPE as a datatype

Oracle Complete PLSQL Reference

37

Part 1 :

PLSQL Course

Control Structure There are three Type of Control Structure 1 IF Condition 2 Case Expression 3 Loop

Oracle Complete PLSQL Reference

38

IF Condition

Oracle Complete PLSQL Reference

39

IF Condition There Are Three Types of IF Statement 1 IF Stamtement with ONLY one Conditon Syntax IF Condition1 then Action1 ; END IF; 2 IF Stamtement with ONLY two Conditons Syntax IF Condition1 then Action1 ; ELSE Action2 ; END IF; 3 IF Stamtement with MORE than two Conditons Syntax IF Condition1 then Action1 ; ELSIF Condition2 then Action2 ; ELSIF Condition3 then Action3 ; ELSIF Condition4 then Action4 ; ELSE action 5; END IF; All conditions in IF statements are Boolean expressions that evaluate to true or false. All Actions in IF Statements are PL/SQL statements You can execute many actions as you like when the actions is TRUE IF Stamtement with ONLY one Conditon

Oracle Complete PLSQL Reference

40

IF Stamtement with ONLY one Conditon

Oracle Complete PLSQL Reference

41

IF Stamtement with ONLY two Conditons

Oracle Complete PLSQL Reference

42

IF Stamtement with MORE than two Conditons

Oracle Complete PLSQL Reference

43

IF Stamtement with MORE than two Conditons

Oracle Complete PLSQL Reference

44

create or replace procedure rep1(p1 number) is vsal number(5); v2 varchar2(20); begin select sal into vsal from emp where empno = p1; if LENGTH(vsal) < 6 then v2 := to_char(vsal,'000000'); dbms_output.put_line(v2); end if; end;

Oracle Complete PLSQL Reference

45

CASE Expression

Oracle Complete PLSQL Reference

46

CASE Expression Create or replace procedure rep1(p1 number) Is V_sal number(5); Begin Select sal Into v_sal From scott.Emp Where empno = p1; v_sal := CASE v_sal When  null then 50 ;                     When  DECLARE 2 TYPE emp_table_struct IS TABLE OF emp.fname%TYPE INDEX BY BINARY_INTEGER; 3 emp_table emp_table_struct; 4 CURSOR emp_cursor IS SELECT fname FROM emp ORDER BY id; 5 v_row NUMBER := 1; 6 BEGIN 7 OPEN emp_cursor; 8 LOOP 9 FETCH emp_cursor INTO emp_table(v_row); 10 EXIT WHEN emp_cursor%NOTFOUND; 11 DBMS_OUTPUT.PUT_LINE(emp_table(v_row)); 12 v_row := v_row + 1; 13 END LOOP; 14 CLOSE emp_cursor; 15 DBMS_OUTPUT.PUT_LINE('Total rows: '||emp_table.COUNT); 16 END; 17 /

DataBase Trigger

What is a mutating and constraining table? "Mutating" means "changing". A mutating table is a table that is currently being modified by an update, delete, or insert statement. When a trigger tries to reference a table that is in state of flux (being changed), it is considered "mutating" and raises an error since Oracle should not return data that has not yet reached its final state. Another way this error can occur is if the trigger has statements to change the primary, foreign or unique key columns of the table off which it fires. If you must have triggers on tables that have referential constraints, the workaround is to enforce the referential integrity through triggers as well. There are several restrictions in Oracle regarding triggers:  A row-level trigger cannot query or modify a mutating table. (Of course, NEW and OLD still can be accessed by the trigger) . Oracle Complete PLSQL Reference

116

A statement-level trigger cannot query or modify a mutating table if the trigger is fired as the result

Is it better to put code in triggers or procedures? What is the difference? In earlier releases of Oracle it was better to put as much code as possible in procedures rather than triggers. At that stage procedures executed faster than triggers as triggers had to be re-compiled every time before executed (unless cached). In more recent releases both triggers and procedures are compiled when created (stored p-code) and one can add as much code as one likes in either procedures or triggers.

Functions Q: What is Fincation? A function is similar to a procedure except that a function must return a value. Function can accept parameters or not The simplified syntax for the CREATE FUNCTION statement is as follows: CREATE [OR REPLACE] FUNCTION function_name [(parameter_name [IN | OUT | IN OUT] type [, ...])] RETURN type {IS | AS} BEGIN function_body END function_name; Oracle Complete PLSQL Reference

117

Function with no parameters

Function with parameters

Oracle Complete PLSQL Reference

118

Function with parameters Function to calculate raise as 10% of the salary

Oracle Complete PLSQL Reference

119

Function to calculate raise as % of the salary

Oracle Complete PLSQL Reference

120

Function to calculate total as sal + comm

Oracle Complete PLSQL Reference

121

Function returns week No of the Month

Oracle Complete PLSQL Reference

122

Functions return name of a Month

Oracle Complete PLSQL Reference

123

Functions return Quartner No of the year

Oracle Complete PLSQL Reference

124

Functions return Julian Date Julian date must be between 1 and 5373484

Functions return name of a specific date Oracle Complete PLSQL Reference

125

Functions return username

Functions return sysdate

Functions return default nationality Oracle Complete PLSQL Reference

126

Functions return Max salary

Position Notation calls for the parameters

Oracle Complete PLSQL Reference

127

Name Notation calls for the parameters

Mixed Name and position Notation calls for the parameters

Oracle Complete PLSQL Reference

128

Database Trigger

Oracle Complete PLSQL Reference

129

DataBase Trigger Q: what is a Trigger ? It is a PLSQL Block that is associated with specific table, view, schema, Database and fire implecitly when a specific event occure Q: what are the trigger’s Types? 1. DataBase Trigger 2. Application Trigger

Fire When specific Database event Occurs (Database) Fire When specific Event Occurs With Particular Application (Forms, report)

Q: what are the objects that the DB trigger associate with ? 1. Table 2. View 3. schema

4. Database

Q: what is the structur of the Trigger Code? Part 1 Trigger Timing After – Before (Tables) – Instead of(View) Mandatory Part 2 Trigger Event 1. DB Event 1. DML Trigger Mandatory Insert , update , update of , delete

Part 3 Optinal

Trigger Type

2. System Event

Create , alter , drop , Logon , logoff , shutdown,startup,servererror

For each row

1. The trigger body executes once for each row affected by the trigger event.

2. use :NEW , :OLD functions For Each Statement 1. The trigger body executed for each bulk of rows affected [Default] by the trigger event . Part 4 Trigger Optional Condition Part 5 Trigger Action Mandatory

When

2. NOT use :NEW , :OLD functions If you want to restirct a specific condition The actions that the trigger will execute when the event occur

Trigger Syntax

Oracle Complete PLSQL Reference

130

Oracle Complete PLSQL Reference

131

Oracle Complete PLSQL Reference

132

Oracle Complete PLSQL Reference

133

DDL Triggers Events BEFORE / AFTER ALTER Oracle Complete PLSQL Reference

1. 134

Avaliable Functions ora_sysevent

BEFORE / AFTER CREATE BEFORE / AFTER DROP BEFORE / AFTER RENAME BEFORE / AFTER ANALYZE BEFORE / AFTER ASSOCIATE STATISTICS BEFORE / AFTER DISASSOCIATE STATISTICS BEFORE / AFTER AUDIT BEFORE / AFTER NOAUDIT BEFORE / AFTER COMMENT BEFORE / AFTER DDL BEFORE / AFTER GRANT BEFORE / AFTER REVOKE BEFORE / AFTER TRUNCATE AFTER SUSPEND

Oracle Complete PLSQL Reference

2. 3. 4. 5. 6. 7. 8. 9. 10. 11. 12. 13. 14. 15. 16. 17. 18. 19. 20. 21. 22. 23. 24. 25. 26.

135

ora_client_ip_address Ora_database_name ora_des_encrypted_password ora_dict_obj_name ora_dict_obj_name_list ora_dict_obj_owner ora_dict_obj_type ora_grantee ora_instance_num ora_is_alter_column ora_is_creating_nested_table ora_is_drop_column ora_is_servererror ora_login_user ora_partition_pos ora_privilege_list ora_revokee ora_server_error ora_server_error_depth ora_server_error_msg ora_server_error_num_params ora_server_error_param ora_sql_txt ora_with_grant_option space_error_info

What is a mutating and constraining table? "Mutating" means "changing". A mutating table is a table that is currently being modified by an update, delete, or insert statement. When a trigger tries to reference a table that is in state of flux (being changed), it is considered "mutating" and raises an error since Oracle should not return data that has not yet reached its final state. Another way this error can occur is if the trigger has statements to change the primary, foreign or unique key columns of the table off which it fires. If you must have triggers on tables that have referential constraints, the workaround is to enforce the referential integrity through triggers as well. There are several restrictions in Oracle regarding triggers: A row-level trigger cannot query or modify a mutating table. (Of course, NEW and OLD still can be accessed by the trigger) . A statement-level trigger cannot query or modify a mutating table if the trigger is fired as the result Is it better to put code in triggers or procedures? What is the difference? In earlier releases of Oracle it was better to put as much code as possible in procedures rather than triggers. At that stage procedures executed faster than triggers as triggers had to be re-compiled every time before executed (unless cached). In more recent releases both triggers and procedures are compiled when created (stored p-code) and one

Oracle Complete PLSQL Reference

136

create table company (product_id number(4) not null, company_id NUMBER(8) not null, company_short_name varchar2(30) not null, company_long_name varchar2(60) ); insert insert insert insert insert insert

into into into into into into

company company company company company company

values(1,1001,'A Inc.','Long Name A Inc.'); values(1,1002,'B Inc.','Long Name B Inc.'); values(1,1003,'C Inc.','Long Name C Inc.'); values(2,1004,'D Inc.','Long Name D Inc.'); values(2,1005,'E Inc.','Long Name E Inc.'); values(2,1006,'F Inc.','Long Name F Inc.');

create table product_audit (product_id number(4) not null, num_rows number(8) not null ); CREATE OR REPLACE TRIGGER myTrigger AFTER INSERT ON company FOR EACH ROW DECLARE BEGIN UPDATE product_audit SET num_rows =num_rows+1 WHERE product_id =:NEW.product_id; IF (SQL%NOTFOUND) THEN INSERT INTO product_audit VALUES (:NEW.product_id,1); END IF; END; / insert into company values(3,1007,'E Inc.','Long Name E Inc.');

Oracle Complete PLSQL Reference

137

Examples SQL> create table emplpyee     (empno number(5), name char(10), sal number(5), comm number(5),total number(5))

SQL> Create or replace trigger Tri1      After update of sal , comm on emp      For each row      Begin      Update emp      Set total = sal+comm      Where sal =:new.sal or comm =:new.comm;      End;

SQL> insert into e values(1,'ali',100,200,null); SQL> insert into e values(2,'mona',200,300,null); SQL> commit;

SQL> update e set sal = 300 where id=1;

ERROR at line 1: ORA­04091: table SCOTT.E is mutating, trigger/function may not see it ORA­06512: at "SCOTT.TRI1", line 2 ORA­04088: error during execution of trigger 'SCOTT.TRI1' Error Calrification IN Oracle you cann’t insrt into table X and run trigger to update the same table But you can run the trigger to update another table b because it is related to internal constraint that violate this issue

Oracle Complete PLSQL Reference

138

Instead OF Trigger

Use instead of trigger when you want to insert or update or delete on unupdatable View (Read Only View) because the instead of trigger works invisibly on the underlying table Name Null? Type ----------------------------------------- -------- ------------------------DEPTNO NOT NULL NUMBER(5) Primary Key DNAME CHAR(20) LOC CHAR(20) Name Null? Type ----------------------------------------- -------- ------------------------EMPNO NOT NULL NUMBER(5) ENAME CHAR(20) SAL NUMBER(5) DEPTNO NUMBER(5) References d:deptno

Oracle Complete PLSQL Reference

139

Create or replace view v As select e.empno , e.ename , e.sal , e.deptno , d.deptno deptatmentID , d.dname , d.loc From e e , d d Where e.deptno = d.deptno

Create or replace trigger Tri1 Instead of insert on v For each row Begin Insert into d Values(:new.deptno , :new.dname ,:new.loc); Insert into E Values(:new.empno , :new.ename ,:new.sal ,:new.deptno); End; Insert into v Values(1,’ahmed’,100,1,1,’sales’,’cairo’); You must insert data into view in the same sequence for that view columns

Q: How do I Enable and Disable the Trigger SQL> Alter trigger Disable|Enable Q: How do I Enable and Disable all trigger for a table SQL> Alter table Disable|Enable Q: How do I Compile the trigger SQL> Alter Trigger compile Q: How do I drop the trigger SQL> drop Trigger

Oracle Complete PLSQL Reference

140

as

System Triggers 1.

DDL Trigers

http://www.psoug.org/reference/ddl_trigger.html DDL Triggers Events BEFORE / AFTER ALTER BEFORE / AFTER CREATE BEFORE / AFTER DROP BEFORE / AFTER RENAME BEFORE / AFTER ANALYZE BEFORE / AFTER ASSOCIATE STATISTICS BEFORE / AFTER DISASSOCIATE STATISTICS BEFORE / AFTER AUDIT BEFORE / AFTER NOAUDIT BEFORE / AFTER COMMENT BEFORE / AFTER DDL BEFORE / AFTER GRANT BEFORE / AFTER REVOKE BEFORE / AFTER TRUNCATE AFTER SUSPEND

Oracle Complete PLSQL Reference

27. 28. 29. 30. 31. 32. 33. 34. 35. 36. 37. 38. 39. 40. 41. 42. 43. 44. 45. 46. 47. 48. 49. 50. 51. 52.

141

Avaliable Functions ora_sysevent ora_client_ip_address Ora_database_name ora_des_encrypted_password ora_dict_obj_name ora_dict_obj_name_list ora_dict_obj_owner ora_dict_obj_type ora_grantee ora_instance_num ora_is_alter_column ora_is_creating_nested_table ora_is_drop_column ora_is_servererror ora_login_user ora_partition_pos ora_privilege_list ora_revokee ora_server_error ora_server_error_depth ora_server_error_msg ora_server_error_num_params ora_server_error_param ora_sql_txt ora_with_grant_option space_error_info

Example No:10 Create Table tets_DDL (server_Event varchar2(50), object_owner varchar2(50), object_name varchar2(50), user_name varchar2(50), system_date date) CREATE OR REPLACE TRIGGER test_DDL BEFORE CREATE or ALTER or DROP ON SCHEMA BEGIN INSERT INTO tets_ddl SELECT ora_sysevent, ora_dict_obj_owner, ora_dict_obj_name, USER, SYSDATE FROM dual; END;

Example No:11 Conn sys/password@ as sysdba; Create table ddl_log (server_event char(40), owner char(20), objectname char(20), text varchar(200), username char(20), transaction_date date); CREATE OR REPLACE TRIGGER ddl_trigger BEFORE CREATE OR ALTER OR DROP ON SCHEMA DECLARE oper varchar2(50); BEGIN SELECT ora_sysevent INTO oper FROM dual; IF oper IN ('CREATE', 'DROP') THEN INSERT INTO ddl_log SELECT ora_sysevent, ora_dict_obj_owner, ora_dict_obj_name, NULL, USER, SYSDATE FROM dual; ELSIF oper = 'ALTER' THEN INSERT INTO ddl_log SELECT ora_sysevent, ora_dict_obj_owner,ora_dict_obj_name, sql_text, USER, SYSDATE FROM sys.gv$open_cursor WHERE UPPER(sql_text) LIKE 'ALTER%'; END IF; END;

Oracle Complete PLSQL Reference

142

CREATE OR REPLACE TRIGGER save_our_db BEFORE DROP OR TRUNCATE ON SCHEMA DECLARE oper varcha2(20); BEGIN SELECT ora_sysevent INTO oper FROM dual; IF oper = 'DROP' THEN RAISE_APPLICATION_ERROR(-20998, 'Attempt To Drop In Production Has Been Logged'); ELSIF oper = 'TRUNCATE' THEN RAISE_APPLICATION_ERROR(-20999, 'Attempt To Truncate A Production Table Has Been Logged'); END IF; END;

DDL Trigger To Prevent Creating Objects That Whose Names Begin With The Letter 'X' CREATE OR REPLACE TRIGGER no_xtabs BEFORE CREATE ON SCHEMA DECLARE x user_tables.table_name%TYPE; BEGIN SELECT ora_dict_obj_name INTO x FROM dual; IF SUBSTR(x, 1, 1) = 'X' THEN RAISE_APPLICATION_ERROR(-20099, 'Table Names Can Not Start With The Letter X'); END IF; END; /

Oracle Complete PLSQL Reference

143

2.

System Triggers

http://www.psoug.org/reference/system_trigger.html AFTER LOGON AFTER STARTUP System Event Trigger Types

BEFORE LOGOFF BEFORE SHUTDOWN AFTER SERVERERROR (does not trap

CREATE TABLE connection_audit (login_date username

DATE, VARCHAR2(30));

CREATE OR REPLACE TRIGGER logon_audit AFTER LOGON on database BEGIN INSERT INTO connection_audit(login_date, username) VALUES (SYSDATE, USER); END;

CREATE TABLE log_logons (sqltext VARCHAR2(25) NOT NULL);

CREATE OR REPLACE PROCEDURE logproc Is Begin INSERT INTO log_logons(sqltext) VALUES(user || ' - ' || TO_CHAR(SYSDATE)|| ' - '||'Logged On' ); End;

CREATE OR REPLACE TRIGGER logintrig AFTER LOGON ON DATABASE CALL logproc

Oracle Complete PLSQL Reference

144

Create table ip (ip_add char(20), user_name char(20), logon_user char(20),

I want to display all object names that has been altered

db_name char(20),

instance_no number(5),

create table w logon_date date);

CREATE OR REPLACE TRIGGER ip_trace (username char(20), AFTER LOGON ON DATABASE

object_name varchar2(255)); IF (ora_sysevent=’LOGON’) THEN INSERT INTO IP OR REPLACE TRIGGER sysevent_trig CREATE BEGIN

VALUES(ora_client_ip_address,user,ora_login_user,Ora_database_name,ora_instance_num,sysdate); END IF; AFTER ALTER ON SCHEMA END;

BEGIN INSERT INTO w VALUES(user,ora_dict_obj_name); END ;

Oracle Complete PLSQL Reference

145

alter table dept add constraint a check (dname is not null); alter user scott identified by scott; I want to display descripted password for the altered user create table encpassword (username char(20), enc_user char(255), encpassword varchar2(255)); CREATE OR REPLACE TRIGGER sysevent_trig AFTER ALTER ON DATABASE BEGIN INSERT INTO encpassword VALUES(user,ora_dict_obj_name,ora_des_encrypted_password); END; Alter user scott identifiec by abc; Select * from encpassword

Oracle Complete PLSQL Reference

146

Server Error Trigger SQL > create table caught_errors (dt date, username varchar2( 30), msg varchar2(512), stmt varchar2(512)); create or replace trigger catch_errors After servererror on database Declare sql_text ora_name_list_t; msg_

varchar2(2000) := null;

stmt_

varchar2(2000) := null;

begin for depth in 1 .. ora_server_error_depth loop msg_ := msg_ || ora_server_error_msg(depth); End loop; For i in 1 .. ora_sql_txt(sql_text) loop stmt_ := stmt_ || sql_text(i); End loop; Insert into caught_errors (dt,username,msg ,stmt )values (sysdate,ora_login_user,msg_,stmt_); end;

Trigger Privelages create trigger create any trigger System Privileges

administer database trigger -- required for ON DATABASE alter any trigger drop any trigger

Oracle Complete PLSQL Reference

147

Triggers Data Dictionary

dba_triggers



all_triggers

user_triggers

You Can Enable And Disable Any Trigger According To the following Codes

Oracle Complete PLSQL Reference

148

Function

Oracle Complete PLSQL Reference

149

1. create or replace function emp_count return number is cnt number(2) := 0; begin select count(*) into cnt from emp ; return (cnt); end; / 2. create or replace function emp_count (p_deptno in number) return number is cnt number(2) := 0; begin select count(*) into cnt from emp where deptno = p_deptno ; return (cnt); end; / 3. update emp set comm = sal where deptno = 10 ; commit; create or replace function fun1 (p1 number , p2 number) return number is begin if p1 = p2 then return (0); else return (1); end if; end; / 4. select ename , sal , sal*0.10 as raise from emp; Create or replace function raise10(p_sal number) Return number Is Begin Return (p_sal * 0.10); Oracle Complete PLSQL Reference

150

End; Create or replace function raise(p_sal number ,p_percentage number ) Return number Is Begin Return (p_sal * p_percentage); End; 5. select ename , sal , comm, nvl(sal,0)+nvl(comm,0) as total from emp; Create or replace function total (p_sal number , p_comm number) return number is Begin return (nvl(p_sal,0)+nvl(p_comm,0)); End; 6. select ename , hiredate , TO_CHAR(hiredate,'W') from emp; Create or replace function week_month(p_date IN date) RETURN NUMBER IS BEGIN RETURN ( TO_NUMBER( TO_CHAR( p_date, 'W' ) ) ); END; 7. select ename, hiredate , TO_CHAR(hiredate, 'fmMonth') as Month_name from emp; Create or replace function Month_Name ( p_date IN DATE ) RETURN VARCHAR2 IS BEGIN RETURN ( TO_CHAR( p_date, 'fmMonth' ) ); END Month_Name; 8. select ename , hiredate , TO_CHAR( hiredate, 'Q' ) from emp where deptno = 10 ;

Oracle Complete PLSQL Reference

151

Create or replace function quarter( p_date IN DATE ) RETURN NUMBER IS BEGIN RETURN ( TO_NUMBER( TO_CHAR( p_date, 'Q' ) ) ); END; 9- Function that return julian date from date select hiredate , TO_CHAR(hiredate, 'J' ) from emp where deptno = 10 ; Create or replace function julianfromdate(p_date IN date) RETURN NUMBER IS BEGIN RETURN (TO_NUMBER(TO_CHAR( p_date, 'J' ) ) ); END; 10- function that return date form julian Create or replace function datefromjulian(p_num IN NUMBER ) RETURN DATE IS BEGIN IF p_num BETWEEN 1 and 5373484 THEN RETURN (TO_DATE(TRUNC(p_num ),'J')); ELSE RAISE_APPLICATION_ERROR (-01854, 'Julian date must be between 1 and 5373484'); END IF; END; 11- Function that return dayname select ename ,hiredate , TO_CHAR( hiredate, 'fmDay') from emp where deptno = 10 ; Create or replace function dayname ( p_date IN DATE ) RETURN VARCHAR2 IS BEGIN RETURN ( TO_CHAR( p_date, 'fmDay' ) ); END; 12. Create Or Replace Function username RETURN VARCHAR2 IS BEGIN Oracle Complete PLSQL Reference

152

RETURN user; END; 13. Function that return current date = sysdate select sysdate from dual; Create Or Replace Function current_date RETURN date IS BEGIN RETURN sysdate; END; 14- Function that default value for nationality column create table employee (name char(4),nationality varchar2(20)); Create Or Replace Function default_nationality RETURN varchar2 IS BEGIN RETURN ‘egyptian’; END; Insert into employee Values('ali', default_nationality); 15- Function that return max_sal_emp select max(sal) from emp; Create Or Replace Function max_sal_emp RETURN number IS v_max_sal number(5); BEGIN Select max(sal) Into v_max_sal From emp; RETURN v_max_sal; END; 16- Function that return statistic select max(sal) , min(sal) , avg(sal) , sum(sal) from emp; Create Or Replace Function Max_Min_Avg_Sum RETURN varchar2 IS v_max_sal number(5); v_min_sal number(5); Oracle Complete PLSQL Reference

153

v_avg_sal number(5); v_sum_sal number(5); BEGIN Select max(sal) , min(sal), avg(sal) , sum(sal) Into v_max_sal , v_min_sal , v_avg_sal , v_sum_sal From emp; RETURN (to_char(v_max_sal) || '-' || to_char(v_min_sal) || '-' || to_char(v_avg_sal) || '-' || to_char(v_sum_sal)); END; 17. CREATE OR REPLACE FUNCTION add_three_numbers( a NUMBER := 0, b NUMBER := 0, c NUMBER := 0 ) RETURN NUMBER IS BEGIN RETURN a + b + c; END; / BEGIN dbms_output.put_line(add_three_numbers(3,4,5)); END; / 18. CREATE OR REPLACE FUNCTION add_three_numbers( a NUMBER := 0, b NUMBER := 0, c NUMBER := 0 ) RETURN NUMBER IS BEGIN RETURN a + b + c; END; / BEGIN dbms_output.put_line(add_three_numbers(a => 4,b => 5,c => 3)); END; 19. CREATE OR REPLACE FUNCTION add_three_numbers( a NUMBER := 0, b NUMBER := 0, c NUMBER := 0 ) RETURN NUMBER IS BEGIN RETURN a + b + c; END; / BEGIN dbms_output.put_line(add_three_numbers(a => 4,b => 5,c => 3)); END; Oracle Complete PLSQL Reference

154

Package

Oracle Complete PLSQL Reference

155

create table dd (deptno number(5),deptname varchar2(30),deptloc varchar2(5)); create sequence sqdept start with 1 increment by 1; CREATE or replace package over_pack  IS / AS Procedure add_dept(dno number,dname varchar2,dloc varchar2); Procedure add_dept(dname varchar2,dloc varchar2); End; / CREATE or replace package BODY over_pack  Is Procedure add_dept(dno number,dname varchar2,dloc varchar2) Is Begin Insert into dd values(dno , dname ,dloc); End;

Procedure add_dept(dname varchar2,dloc varchar2) Is Begin Insert into dd values(sqdept.nextval , dname ,dloc); End; End; / exec over_pack.add_dept(’design’,’cairo’); exec over_pack.add_dept(1,’sales’,’alex’);

Oracle Complete PLSQL Reference

156

CREATE or replace package over_pack  Is function total  (v_sal number , v_comm number)return number; function max_sal_emp return number; End; CREATE or replace package body over_pack  Is function total(v_sal number , v_comm number)  return number is Begin return (nvl(v_sal,0)+nvl(v_comm,0)); End; Function max_sal_emp  RETURN number IS v_max_sal number(5); BEGIN Select max(sal) Into v_max_sal From emp; RETURN (v_max_sal); END; End; / select sal , comm, over_pack.total(sal,comm) from emp ; select over_pack.max_sal_emp from dual;

Oracle Complete PLSQL Reference

157

Oracle Complete PLSQL Reference

158

Oracle Complete PLSQL Reference

159

System Package

Oracle Complete PLSQL Reference

160

Oracle Complete PLSQL Reference

161

DBMS_ALERT( 6 ) DBMS_DEBUG( 1 ) dbms_lock( 1 ) DBMS_REDEFINITION( 1 ) dbms_sql( 27 ) dbms_xmlschema( 2 ) UTL_COMPRESS( 1 ) utl_raw( 27 )

dbms_application_info( 4 ) DBMS_FGA( 1 ) DBMS_METADATA( 2 ) DBMS_REPAIR( 4 ) dbms_stats( 12 ) htp( 1 ) UTL_FILE( 9 ) UTL_SMTP( 1 )

Oracle Complete PLSQL Reference

DBMS_AQADM( 3 ) DBMS_FILE_TRANSFER( 1 ) DBMS_OBFUSCATION_TOOLKIT( 6 ) dbms_rowid( 7 ) DBMS_TRACE( 2 ) ORA Error( 13 ) UTL_HTTP( 1 ) UTL_TCP( 1 )

162

dbms_crypto( 8 ) dbms_flashback( 3 ) dbms_output( 16 ) dbms_scheduler( 1 ) dbms_utility( 15 ) ORA( 18 ) utl_i18n( 1 )

DBMS_DB( 1 ) dbms_job( 8 ) DBMS_PIPE( 13 ) DBMS_SESSION( 1 ) DBMS_WARNING( 2 ) outln_pkg( 1 ) UTL_INADDR( 1 )

dbms_ddl( 1 ) dbms_lob( 17 ) DBMS_RANDOM( 12 ) dbms_space( 1 ) dbms_xmlquery( 1 ) TEXT_IO( 1 ) UTL_MAIL( 1 )

Implicit Cursor http://www.java2s.com/Tutorial/Oracle/0500__Cursor/sqlnotfound.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/UsingSELECTinaCursor.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Cursorforobjecttable.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Cursorwithorderby.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Cursorforaggregatefunction.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/FetchingAcrossCommitsExample2.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/CursorFORLoop.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Closecursorinexcpetionhandler.htm SQL > Create or replace procedure a Is Cursor Emp_Rec_Cur is select ename , deptno from emp; Begin for i in emp_rec_cur  loop            ­­ implicit open and implicit Fetch if    i.deptno= 20  then dbms_output.put_line(i.ename || ' ' || i.deptno); end if; end loop;                               ­­ implicit close and implicit loop Exit end; the prvious example is equal to next example SQL > Create or replace procedure a Is Begin for i in (select ename , deptno from emp)  loop ­­ implicit open and implicit Fetch if    i.deptno= 20  then dbms_output.put_line(i.ename || ' ' || i.deptno); end if; end loop;                                                                       ­­  implicit close and implicit loop Exit end;

SQL%ROWCOUNT and SQL%BULK_ROWCOUNT http://www.java2s.com/Tutorial/Oracle/0500__Cursor/usingSQLBULKROWCOUNTandSQLROWCOUNT.htm

Use cursor subquery http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Usethecursorsubquery.htm Nested Cursor http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Nestedcursor.htm

VARRAY of Cursor http://www.java2s.com/Tutorial/Oracle/0500__Cursor/VARRAYofCursor.htm

Assigning different queries to the same cursor variable Ref Cursor http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Assigningdifferentqueriestothesamecursorvariable.htm Oracle Complete PLSQL Reference

163

Execute immediate statement BEGIN FOR i IN (SELECT table_name FROM user_tables WHERE table_name = 'DEPT2' ) LOOP ;'EXECUTE IMMEDIATE 'DROP TABLE dummy 6 7 ;END LOOP 8 9 10 END; http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Returninformationusingcursorstatusvariables.htm

Can one use dynamic SQL statements from PL/SQL? Starting from Oracle8i one can use the "EXECUTE IMMEDIATE" statement to execute dynamic SQL and PL/SQL statements (statements created at run-time). Look at these examples. Note that statements are NOT terminated by semicolons: EXECUTE IMMEDIATE 'CREATE TABLE x (a NUMBER)'; -- Using bind variables... sql_stmt := 'INSERT INTO dept VALUES (:1, :2, :3)'; EXECUTE IMMEDIATE sql_stmt USING dept_id, dept_name, location; -- Returning a cursor... sql_stmt := 'SELECT * FROM emp WHERE empno = :id'; EXECUTE IMMEDIATE sql_stmt INTO emp_rec USING emp_id; One can also use the older DBMS_SQL package (V2.1 and above) to execute dynamic statements. Look at these examples: CREATE OR REPLACE PROCEDURE DYNSQL AS cur integer; rc integer; BEGIN cur := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(cur, 'CREATE TABLE X (Y DATE)', DBMS_SQL.NATIVE); rc := DBMS_SQL.EXECUTE(cur); DBMS_SQL.CLOSE_CURSOR(cur); END; / More complex DBMS_SQL example using bind variables: CREATE OR REPLACE PROCEDURE DEPARTMENTS(NO IN DEPT.DEPTNO%TYPE) AS v_cursor integer; v_dname char(20); v_rows integer; BEGIN v_cursor := DBMS_SQL.OPEN_CURSOR; DBMS_SQL.PARSE(v_cursor, 'select dname from dept where deptno > :x', DBMS_SQL.V7); DBMS_SQL.BIND_VARIABLE(v_cursor, ':x', no); DBMS_SQL.DEFINE_COLUMN_CHAR(v_cursor, 1, v_dname, 20); v_rows := DBMS_SQL.EXECUTE(v_cursor); loop if DBMS_SQL.FETCH_ROWS(v_cursor) = 0 then exit; end if; DBMS_SQL.COLUMN_VALUE_CHAR(v_cursor, 1, v_dname); DBMS_OUTPUT.PUT_LINE('Deptartment name: '||v_dname); end loop; DBMS_SQL.CLOSE_CURSOR(v_cursor); EXCEPTION when others then Oracle Complete PLSQL Reference

164

sqlerrm); END; /  Back to top

DBMS_SQL.CLOSE_CURSOR(v_cursor); raise_application_error(-20000, 'Unknown Exception Raised: '||sqlcode||' '||

of file Execute procedure

1. 2. 3. 4.

exec rep1; exec rep1()p1,p2,p3,……; call rep1(); call rep1(p1,p2,p3,…….); Triggers

Oracle Complete PLSQL Reference

165

Table data type http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Createandusereferencecursor.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/Referencevalueinacursorbycursorvariable.htm Function http://www.java2s.com/Tutorial/Oracle/0480__PL-SQLProgramming/CodewithConditionalControltoAvoidanException.htm http://www.java2s.com/Tutorial/Oracle/0480__PL-SQLProgramming/CodewithExplicitHandlerforPredefinedException.htm http://www.java2s.com/Tutorial/Oracle/0480__PL-SQLProgramming/Handlingexceptionswithouthaltingtheprogram.htm IN OUT PARAMETER http://www.java2s.com/Tutorial/Oracle/0500__Cursor/TheuseofREFCURSOR.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/OpenSYSREFCURSORforselectfrom.htm http://www.java2s.com/Tutorial/Oracle/0500__Cursor/SYSREFCURSORtypeparameter.htm

Oracle Complete PLSQL Reference

166

While Loop http://www.java2s.com/Tutorial/Oracle/0440__PL-SQL-Statements/ReversedFORLOOP.htm http://www.adp-gmbh.ch/ora/plsql/loops.html https://support.us.oracle.com/oip/faces/secure/srm/sr/SRQueue.jspx?mc=true https://login.oracle.com/mysso/signon.jsp? site2pstoretoken=v1.2~97B77393~56D799A0127BA50DC728218D093398C3E7DC7FBF437396E2 DF8C88659E2568533223ED388A5A74C7CE50A6B563DA6224E2FE03819119B6DD1568AE6C9280 AB2EDCDECBBDD876929B5A9F5D0C72951FDCE134763C3783B3DFACB6CED8B35EA6CC1CF29A9 2BAA0E40C94B0B59C78A8AA97086082846113AC3E082477225EF2359275DE1F014672AC086F85 A66620BFBDAB778B2E5A6D04E0641CF70781A264F3C9EE35CFEC74333D63B3570160E466D4390 A005E5988628900&p_error_code=&p_submit_url=https%3A%2F%2Flogin.oracle.com%2Fsso %2Fauth&p_cancel_url=http%3A%2F%2Fgcca.oraclecorp.com =%2Fcca&ssousername=&subscribername https://login.oracle.com/mysso/signon.jsp? site2pstoretoken=v1.2~B483CC4E~8A17DE85F48237269E6D418A2D3B532BF6B825EBC625C51F D063482AE69E7EB1B7E38AEF36FA299222FB6EB1EE7E34B0DC424060688F88C2241F59A23D04F 3E37FE9AD514E1C692B8BD63EA50EB5A6510493DD38C1E272779A451A13D05CB235AD10FE3A1 1658C15E94EE612F4B74D190699D28ACAE02CA2213BB826001290456A80A25F7EE2D6C99261B0 5A83CD01EAB5FEE046D837278283E8C3F7E28198BAA653F3C73A6FFC6B39B19ACD78D5EDAC9C E0C22B7B5F17349A1312F92CB33D4C25CE5C83F0768185C830F3F292E87C413AC60A0775EF16C 324913DCBF1A7F1A9D25E779E5B91F1350602B1F083E5812CDA7B4A2BD87D6317&p_error_code =&p_submit_url=https%3A%2F%2Flogin.oracle.com%2Fsso%2Fauth&p_cancel_url=https%3A%2F =%2Fsupport.us.oracle.com%2Foip&ssousername=&subscribername https://login.oracle.com/mysso/signon.jsp? site2pstoretoken=v1.2~B483CC4E~23E6FB45EB4FE6929831F3A33F813893C1D08307A3F8A92A A3484C34FF3229B41916D02D6C8610D11A20FCE7DF40F64B70506A05058A71C3E56EE66E25DBC CD6B8834A62BB8CD4371A40D66106E03A166297BAD9E86E8A419F45FCD1CDB2278BB4E534703 9AED42D290AD988AC97C5977896884568F4C86E545344B0079CAB3DA03435F70B45D1D2DD73C B25930116BFC56B8EDDC9863698C3465FE67D524D229537AAFBF483E0CC33D838D654E6D4748 356753D3EF371FECA7F8B482995D61F8430328F872CE9E6DAC0580B0A73C727699C7F402C9526 09B21A3263A306C1E4DE7CE0A56893155771D173674350EE77&p_error_code=&p_submit_url=htt ps%3A%2F%2Flogin.oracle.com%2Fsso%2Fauth&p_cancel_url=https%3A%2F =%2Fsupport.us.oracle.com%2Foip&ssousername=&subscribername

Oracle Complete PLSQL Reference

167

part 2 REATE OR REPLACE PROCEDURE pcalled(TabX DBMS_SQL.VARCHAR2S) IS BEGIN -- do something with TabX from database B null; END;

Oracle Complete PLSQL Reference

168

Oracle Supplied Packages Thes packages are got from the following URL http://www.ss64.com/orap/

Packages marked * are new in 9.2 Package       Description DBMS_ALERT    Notify a database event (asynchronous) DBMS_APPLICATION_INFO               Register an application name with the database               for auditing or performance tracking.               Application info can be pushed into  V$SESSION/V$SESSION_LONGOPS   DBMS_AQ       Add a message (of a predefined object type) onto a queue                or dequeue a message.   DBMS_AQADM    Administer a queue or queue table                for messages of a predefined object type.   DBMS_AQELM    Configure Advanced Queuing               asynchronous notification by e­mail and HTTP. *   DBMS_BACKUP_RESTORE               Normalize filenames on Windows NT platforms.   DBMS_DDL      Access SQL DDL statements from a stored procedure,               provides special administration operations                not available as DDLs.   DBMS_DEBUG    Implement server­side debuggers and provide a way to                debug server­side PL/SQL program units.    DBMS_DEFER    User interface to a replicated transactional deferred                RPC facility. Requires the Distributed Option.    Oracle Complete PLSQL Reference

169

DBMS_DEFER_QUERY               Permit querying the deferred remote procedure calls (RPC)               queue data that is not exposed through views.               Requires the Distributed Option.    DMBS_DEFER_SYS               The system administrator interface to a replicated                transactional deferred RPC facility.               Requires the Distributed Option.   DBMS_DESCRIBE               Describe the arguments of a stored procedure               with full name translation and security checking.   DBMS_DISTRIBUTED_TRUST_ADMIN               Maintain the Trusted Database List, which is used to                determine if a privileged database link from a particular                server can be accepted. DBMS_ENCODE   Encode???   DBMS_FGA      Fine­grained security functions. *   DMBS_FLASHBACK               Flash back to a version of the database at a specified               wall­clock time or a specified system change                number (SCN). *   DBMS_HS_PASSTHROUGH               Send pass­through SQL statements to non­Oracle systems.               (via Heterogeneous Services)   DBMS_IOT      Create a table into which references to the chained rows                for an Index Organized Table can be placed using the                ANALYZE command.    DBMS_JOB      Schedule PL/SQL procedures that you want performed at                periodic intervals; also the job queue interface.    DBMS_LDAP     Functions and procedures to access data from               LDAP servers. *   DBMS_LIBCACHE               Prepares the library cache on an Oracle instance by                extracting SQL and PL/SQL from a remote instance and               compiling this SQL locally without execution. *   DBMS_LOB      General purpose routines for operations on Oracle Large               Object (LOBs) datatypes ­ BLOB, CLOB (read­write), Oracle Complete PLSQL Reference

170

              and BFILEs (read­only).    DBMS_LOCK     Request, convert and release locks through Oracle Lock                Management services.   DBMS_LOGMNR   Functions to initialize and run the log reader.    DBMS_LOGMNR_CDC_PUBLISH               Identify new data that has been added to, modified, or                removed from, relational tables and publish the changed                data in a form that is usable by an application. *   DBMS_LOGMNR_CDC_SUBSCRIBE               View and query the change data that was captured                and published with the DBMS_LOGMNR_CDC_PUBLISH package. *   DBMS_LOGMNR_D               Query the dictionary tables of the current database, and                create a text based file containing their contents.   DBMS_METADATA               Retrieve complete database object definitions (metadata)                from the dictionary. *   DBMS_MVIEW    Refresh snapshots that are not part of the same                refresh group and purge logs. DBMS_SNAPSHOT is a synonym.   DBMS_OBFUSCATION_TOOLKIT               Procedures for Data Encryption Standards.   DBMS_ODCI     Get the CPU cost of a user function based on the                elapsed time of the function. *   DBMS_OFFLINE_OG               Public APIs for offline instantiation of master groups.   DBMS_OFFLINE_SNAPSHOT               Public APIs for offline instantiation of snapshots.   DBMS_OLAP     Procedures for summaries, dimensions, and query rewrites.   DBMS_ORACLE_TRACE_AGENT               Client callable interfaces to the Oracle TRACE               instrumentation within the Oracle7 Server.   DBMS_ORACLE_TRACE_USER               Public access to the Oracle release 7 Server                Oracle TRACE instrumentation for the calling user.   Oracle Complete PLSQL Reference

171

DBMS_OUTLN    Interface for procedures and functions associated with                management of stored outlines. Synonymous with OUTLN_PKG   DBMS_OUTLN_EDIT               Edit an invoker's rights package. *   DBMS_OUTPUT   Accumulate information in a buffer so that it can be                retrieved out later.   DBMS_PCLXUTIL Intra­partition parallelism for creating partition­wise                local indexes.   DBMS_PIPE     A DBMS pipe service which enables messages to be sent                between sessions.   DBMS_PROFILER A Probe Profiler API to profile PL/SQL applications               and identify performance bottlenecks.               To install this run profload.sql(as SYS) and proftab.sql(as  user)   DBMS_RANDOM   A built­in random number generator.               Options to generate random numbers within a range or  distribution.   DBMS_RECTIFIER_DIFF               APIs used to detect and resolve data inconsistencies                between two replicated sites.   DBMS_REDEFINITION               Reorganise a table (change it's structure) while it's               still online and in use. *   DBMS_REFRESH  Create groups of snapshots that can be refreshed together               to a transactionally consistent point in time.               Requires the Distributed Option.    DBMS_REPAIR   Repair data corruption.   DBMS_REPCAT   Administer and update the replication catalog and environment.               Requires the Replication Option.   DBMS_REPCAT_ADMIN               Create users with the privileges needed by the symmetric                replication facility. Requires the Replication Option.   DBMS_REPCAT_INSTATIATE               Instantiates deployment templates.               Requires the Replication Option.   Oracle Complete PLSQL Reference

172

DBMS_REPCAT_RGT               Define and maintain refresh group templates.                Requires the Replication Option. DBMS_REPUTIL               Generate shadow tables, triggers, and packages                for table replication.   DBMS_RESOURCE_MANAGER               Maintain plans, consumer groups, and plan directives;                also provides semantics so that you may group together                changes to the plan schema.    DBMS_RESOURCE_MANAGER_PRIVS               Maintain privileges associated with resource consumer groups.    DBMS_RESUMABLE               Suspend large operations that run out of space or reach space                limits after executing for a long time, fix the problem, and                make the statement resume execution.   DBMS_RLS      Row level security administrative interface.   DBMS_ROWID    Procedures to create rowids and to interpret their contents.    DBMS_SESSION  Access to SQL ALTER SESSION statements, and other session                information, from stored procedures.   DBMS_SHARED_POOL               Keep objects in shared memory, so that they will not be aged               out with the normal LRU mechanism.   DBMS_SNAPSHOT               Synonym for DBMS_MVIEW   DBMS_SPACE    Segment space information not available through standard SQL.               How much space is left before a new extent gets allocated?               How many blocks are above the segments High Water Mark?               How many blocks are in the free list(s)   DBMS_SPACE_ADMIN               Tablespace and segment space administration not available                through the standard SQL.   DBMS_SQL      Use dynamic SQL to access the database.   DBMS_STANDARD                Language facilities that help your application interact                with Oracle. Oracle Complete PLSQL Reference

173

 

Oracle Complete PLSQL Reference

174

DBMS_STATS    View and modify optimizer statistics gathered for database  objects.In a small test environment this allows faking the stats to simulate running a large production database.   DBMS_TRACE    Routines to start and stop PL/SQL tracing.   DBMS_TRANSACTION               Access to SQL transaction statements from stored                procedures and monitors transaction activities.   DBMS_TRANSFORM               An interface to the message format transformation features                of Oracle Advanced Queuing. *   DBMS_TTS      Check if a transportable set is self­contained.   DBMS_TYPES    Constants, which represent the built­in and user­defined  types. DBMS_URL      Oracle Spatial connection_type ?? DBMS_UTILITY  Utility routines, Analyze, Time, Conversion etc.   DBMS_WM       Database Workspace Manager (long transactions) *   DBMS_XMLGEN   Convert the results of a SQL query to a canonical XML format.  *   DMBS_XMLQUERY               Database­to­XMLType functionality. *   DBMS_XMLSAVE               XML­to­database­type functionality. *   DEBUG_EXTPROC               Debug external procedures on platforms with debuggers                that can attach to a running process.   OUTLN_PKG     Synonym of DBMS_OUTLN.   PLITBLM       Handle index­table operations.(Don't call directly) SDO_CS,SDO_GEOM,SDO_LRS,SDO_MIGRATE,SDO_TUNE               see Oracle Spatial User's Guide and Reference                Spatial packages are installed in user MDSYS with public  synonyms. STANDARD      Types, exceptions, and subprograms which are Oracle Complete PLSQL Reference

175

              available automatically to every PL/SQL program.  UTL_COLL      Collection locators ­ query and update from a PL/SQL program.   UTL_ENCODE    Encode RAW data into a standard encoded format               so that the data can be transported between hosts. *   UTL_FILE      Read and write OS text files via PL/SQL.                A restricted version of standard OS stream file I/O.    UTL_HTTP      Enable HTTP callouts from PL/SQL and SQL to access data                on the Internet or to call Oracle Web Server Cartridges.   UTL_INADDR    A procedure to support internet addressing.   UTL_PG        Convert COBOL numeric data into Oracle numbers                and convert Oracle numbers into COBOL numeric data.    UTL_RAW       SQL functions for RAW datatypes that concat,                substr, etc. to and from RAWS.   UTL_REF       Enable a PL/SQL program to access an object by providing a                reference to the object.   UTL_SMTP      Send SMTP email. The mailer program needs to run on the  server,               but can be invoked from a client.   UTL_TCP       Simple TCP/IP­based communication between servers and the  outside world.     UTL_URL       Escape and unescape mechanism for URL characters.    ANYDATA TYPE  A self­describing data instance TYPE.   ANYDATASET TYPE               Describe a given TYPE plus a set of data instances of that  type.   ANYTYPE TYPE  Contains a type description of any persistent SQL type,               named or unnamed, including object types and collection types. See also EXEC ­ Execute a PL/SQL package DESC ­ Describe a package Related Views                       ALL_ARGUMENTS        USER_ARGUMENTS Oracle Complete PLSQL Reference

176

 DBA_OBJECTS          ALL_OBJECTS          USER_OBJECTS         SYS_OBJECTS                        ALL_PROCEDURES       USER_PROCEDURES  DBA_SOURCE           ALL_SOURCE           USER_SOURCE 

Oracle Complete PLSQL Reference

177

2. Morgan Library vip vip

Version

Last Modified

Comment

Active Session History

Topic

11gR1

25­Dec­2007

­

Add Binding Clause

11gR1

19­Sep­2007

­

ADDM Demo

11gR1

01­Feb­2008

­

ADR Command Interpreter

11gR1

09­Aug­2008

­

Advanced Compression

11gR1

09­Nov­2008

Advanced Queuing Demo

11gR1

05­Mar­2008

­

Analytic Functions

11gR1

16­Oct­2007

­

Analyze

11gR1

09­Jul­2007

­

Anonymous Block

11gR1

21­Jul­2007

­

Anydata Data Type

11gR1

28­Jul­2007

­

Application Server

10.1.2.0.2

07­Feb­2007

­

Application Server

10.1.3.0.0

07­Feb­2007

­

Archive Logs

11gR1

06­Oct­2007

­

Array Processing

11gR1

18­Aug­2008

­

Arrays: Index by BINARY_INTEGER

11gR1

07­Jul­2007

­

Arrays: Index by VARCHAR2

11gR1

07­Jul­2007

­

AS OF Queries

11gR1

14­Sep­2007

­

ASH

11gR1

25­Dec­2007

­

Associate Statistics

11gR1

03­Jan­2008

­

Associative Arrays

11gR1

07­Jul­2007

­

Audit Vault

10.2.3

14­Jun­2008

­

Auditing

11gR1

06­Aug­2007

­

AUTHID (DEFINER) and CURRENT_USER)

11gR1

01­Sep­2008

­

Automatic Diagnostic Repository

11gR1

28­Sep­2007

­

Automatic Workload Repository

11gR1

17­Aug­2007

­

Automatic Workload Repository Report

11gR1

17­Aug­2007

­

Autonomous Transactions

11gR1

30­Jan­2008

­

Autotrace

11gR1

08­Jul­2007

­

AWR

11gR1

17­Aug­2007

­

AWR Report

11gR1

17­Aug­2007

­

Backup & Recovery

10gR2

07­Mar­2006

­

B*Tree Indexes

11gR1

03­Nov­2008

Bidirectional Cursor

11gR1

06­Aug­2007

­

Bind Variables

11gR1

20­Jul­2007

­

Bitmap Indexes

11gR1

03­Nov­2008

Bitmap Join Indexes

11gR1

03­Nov­2008

BLAST_CUR

11gR1

14­Dec­2007

­

Block Change Tracking

11gR1

20­Jul­2007

­

Block Dump

11gR1

16­Oct­2007

­

Breaking Oracle (demos from UKOUG  presentation)

11gR1

03­Dec­2008

BSQ Files

11gR1

19­Oct­2007

­

Built­in Packages

11gR1

06­Oct­2007

­

Buffer Pool

11gR1

15­Jul­2007

­

Bulk Binding / Bulk Collection

11gR1

17­Aug­2008

­

CASE Function

11gR1

15­Aug­2007

­

Cast Function

11gR1

21­Jul­2007

­

Chained Rows

11gR1

30­Jul­2007

­

Change Data Capture ­ Sync

11gR1

01­Jun­2008

­

Change Data Capture ­ HotLog

11gR1

01­Jun­2008

­

Change Data Capture ­ AutoLog

10gR2

­

­

Oracle Complete PLSQL Reference

178

Character Sets

11gR1

30­Jul­2007

­

Character Set Functions

11gR1

21­Jul­2007

­

Check Constraint

11gR1

25­Nov­2007

­

Clustering Factor

11gR1

12­Aug­2007

­

Clusters

11gR1

20­Jul­2007

­

Codd's Rules

­

07­Jul­2007

­

Collections

11gR1

30­Nov­2008

Collection Functions

11gR1

08­Oct­2007

­

Colored SQL

11gR1

17­Aug­2007

­

COLUMN_VALUE

11gR1

25­Aug­2007

­

Commit

11gR1

07­Jul­2007

­

Common Table Expressions

11gR1

10­Feb­2008

­

Compilation: Interpreted and Native

11gR1

09­Aug­2007

­

Compound Triggers

11gR1

12­Aug­2007

­

Composite Partitioning

11gR1

25­Nov­2007

­

Compressed Indexes

11gR1

09­Nov­2008

Compressed Tables

11gR1

09­Nov­2008

Conditional Compilation

11gR1

25­Nov­2007

­

Conditions

11gR1

24­Nov­2007

­

Connect By

11gR1

26­Nov­2008

Constants

11gR1

21­Aug­2007

­

Constraints

11gR1

29­Feb­2008

­

Consumer Groups

11gR1

25­Dec­2007

­

Contexts

11gR1

06­Oct­2007

­

Continue Statement

11gR1

09­Aug­2007

­

Control Files

11gR1

16­Nov­2008

Control Structures

11gR1

19­Dec­2007

­

Conversion Functions

11gR1

04­Apr­2008

­

Create Database

11gR1

01­May­2008

­

Create Schema

11gR1

08­Jul­2007

­

Cross Tabulation and Pivot Operator

11gR1

02­Oct­2007

­

CRS_STAT

11gR1

07­Feb­2006

­

CTX_DDL

11gR1

24­Dec­2007

­

Cube

11gR1

06­Oct­2007

­

Cursor Sharing

11gR1

26­Oct­2007

­

Cursors & Cursor Loops

11gR1

19­Dec­2007

­

DANGLING

11gR1

23­Nov­2007

­

Data Control Language (DCL)

11gR1

07­Jul­2007

­

Data Dictionary

11gR1

02­Sep­2008

­

Data Files

11gR1

07­Oct­2007

­

Data Guard

10gR2

30­May­2007

Physical Only

Data Integrity

11gR1

26­Oct­2007

­

Data Mining Functions

11gR1

05­Oct­2007

­

Data Pump (API)

11gR1

27­Dec­2007

­

Data Pump (Executable)

11gR1

07­Sep­2008

­

Data Types & SubTypes

11gR1

09­Oct­2007

­

Database

11gR1

01­May­2008

­

Database Links

11gR1

23­Nov­2007

­

Date Functions

11gR1

08­Nov­2008

DBMSOBJG

11gR1

08­Jul­2007

­

DBMS_ADDM

11gR1

16­Nov­2007

­

DBMS_ADVANCED_REWRITE

11gR1

11­Aug­2007

­

DBMS_ADVISOR

11gR1

01­Feb­2008

­

DBMS_ALERT

11gR1

08­Jul­2007

­

DBMS_AMD

11gR1

08­Jul­2007

­

DBMS_APPLICATION_INFO

11gR1

06­Jan­2008

­

Oracle Complete PLSQL Reference

179

DBMS_APPLY_ADM

11gR1

12­Dec­2007

incomplete

DBMS_AQ

11gR1

05­Nov­2007

­

DBMS_AQADM

11gR1

06­Apr­2008

­

DBMS_AQELM

11gR1

08­Oct­2007

­

DBMS_ASSERT

11gR1

12­Aug­2007

­

DBMS_ASYNCRPC_PUSH

11gR1

08­Jul­2007

­

DBMS_AUTO_TASK

11gR1

24­Aug­2007

­

DBMS_AUTO_TASK_ADMIN

11gR1

10­Oct­2007

­

DBMS_AUTO_TASK_EXPORT

11gR1

10­Oct­2007

­

DBMS_AUTO_TASK_IMMEDIATE

11gR1

10­Oct­2007

­

DBMS_AW

11gR1

15­Feb­2008

­

DBMS_AW_STATS

11gR1

15­Feb­2008

­

DBMS_BACKUP_RESTORE

11gR1

28­May­2008

­

DBMS_CAPTURE_ADM

11gR1

17­Oct­2007

­

DBMS_CDC_PUBLISH

11gR1

20­Sep­2008

­

DBMS_CDC_SUBSCRIBE

11gR1

18­Oct­2007

­

DBMS_CDC_UTILITY

11gR1

20­Sep­2008

­

DBMS_CHANGE_NOTIFICATION

11gR1

07­Apr­2008

­

DBMS_CLUSTDB

11gR1

08­Jul­2007

­

DBMS_COMPARISON

11gR1

30­Oct­2008

­

DBMS_CONNECTION_POOL

11gR1

12­Aug­2007

­

DBMS_CQ_NOTIFICATIONS

11gR1

25­Dec­2007

­

DBMS_CRYPTO

11gR1

11­Aug­2007

­

DBMS_CRYPTO_TOOLKIT_TYPES

11gR1

29­Jul­2007

­

DBMS_CSX_ADMIN

11gR1

13­Sep­2007

­

DBMS_CUBE

11gR1

15­Feb­2008

­

DBMS_DATAPUMP

11gR1

27­Dec­2007

­

DBMS_DBLINK

11gR1

29­Jul­2007

­

DBMS_DB_VERSION

11gR1

25­Nov­2007

­

DBMS_DBVERIFY

11gR1

23­Aug­2007

­

DBMS_DDL

11gR1

18­Mar­2008

­

DBMS_DDL_INTERNAL

11gR1

18­Aug­2007

­

DBMS_DESCRIBE

11gR1

18­Dec­2007

­

DBMS_DG

11gR1

24­Aug­2007

­

DBMS_DIMENSION

11gR1

04­Dec­2007

­

DBMS_DISTRIBUTED_TRUST_ADMIN

11gR1

16­Mar­2008

­

DBMS_DRS

11gR1

14­Dec­2007

­

DBMS_EDITIONS_UTILITIES

11gR1

13­Sep­2007

­

DBMS_EPG

11gR1

18­Mar­2008

­

DBMS_ERRLOG

11gR1

24­Aug­2007

­

DBMS_EXPFIL

11gR1

25­Dec­2007

­

DBMS_EXTENDED_TTS_CHECKS

11gR1

07­Dec­2007

­

DBMS_FBT

11gR1

26­Sep­2008

­

DBMS_FEATURE_USAGE

11gR1

17­Aug­2007

­

DBMS_FEATURE_USAGE_REPORT

11gR1

17­Aug­2007

­

DBMS_FGA

11gR1

24­Dec­2007

­

DBMS_FILE_TRANSFER

11gR1

09­Aug­2007

­

DBMS_FLASHBACK

11gR1

14­Sep­2007

­

DBMS_FREQUENT_ITEMSET

11gR1

18­Mar­2008

­

DBMS_HA_ALERTS

11gR1

14­Aug­2007

­

DBMS_HA_ALERTS_PRVT

11gR1

14­Aug­2007

­

DBMS_HM

11gR1

24­Sep­2007

­

DBMS_HPROF

11gR1

23­Aug­2007

­

DBMS_I_INDEX_UTL

11gR1

14­Mar­2008

­

DBMS_INDEX_UTL

11gR1

09­Aug­2007

­

DBMS_INDEXING

11gR1

09­Aug­2007

­

Oracle Complete PLSQL Reference

180

DBMS_IOT

11gR1

17­Aug­2007

DBMS_IR

11gR1

13­Sep­2007

­

DBMS_JOB

11gR1

24­Aug­2007

See DBMS_SCHEDULER too

DBMS_LCR

11gR1

29­Jul­2007

­

DBMS_LDAP

11gR1

13­Dec­2007

­

DBMS_LOB

11gR1

25­Sep­2007

­

DBMS_LOBUTIL

11gR1

26­Sep­2007

­

DBMS_LOCK

11gR1

18­Aug­2007

­

DBMS_LOGMNR

11gR1

25­Dec­2007

­

DBMS_LOGMNR_D

11gR1

24­Apr­2008

­

DBMS_LOGSTDBY

11gR1

17­Sep­2007

­

DBMS_MANAGEMENT_PACKS

11gR1

26­Sep­2007

­

DBMS_METADATA

11gR1

29­Jul­2008

­

DBMS_METADATA_UTIL

11gR1

11­Apr­2008

­

DBMS_MONITOR

11gR1

01­Feb­2008

­

DBMS_MVIEW

11gR1

04­Dec­2007

­

DBMS_NETWORK_ACL_ADMIN

11gR1

26­Dec­2007

­

DBMS_NETWORK_ACL_UTILITY

11gR1

09­Aug­2007

­

DBMS_OBFUSCATION_TOOLKIT

­

­

­

Deprecated See DBMS_CRYPTO

DBMS_OBJECT_UTILS

11gR1

17­Dec­2007

­

DBMS_ODCI

11gR1

09­Aug­2007

­

DBMS_OUTLN

11gR1

30­Mar­2008

­

DBMS_OUTLN_EDIT

11gR1

30­Mar­2008

­

DBMS_OUTPUT

11gR1

10­Jul­2007

­

DBMS_PCLXUTIL

11gR1

10­Jul­2007

­

DBMS_PREDICTIVE_ANALYTICS

11gR1

13­Aug­2007

­

DBMS_PREPROCESSOR

11gR1

13­Aug­2007

­

DBMS_PROFILER

11gR1

20­Aug­2007

­

DBMS_PROPAGATION_ADM

11gR1

30­Mar­2008

­

DBMS_RANDOM

11gR1

10­Jul­2007

See DBMS_CRYPTO too

DBMS_RECTIFIER_DIFF

11gR1

30­Oct­2008

­

DBMS_RECTIFIER_FRIENDS

11gR1

10­Jul­2007

­

DBMS_REDEFINITION

11gR1

29­Mar­2008

­

DBMS_REFRESH

11gR1

20­Aug­2007

­

DBMS_REGISTRY

11gR1

17­Aug­2008

­

DBMS_REGISTRY_SERVER

11gR1

24­Dec­2007

­

DBMS_REGXDB

11gR1

20­Aug­2007

­

DBMS_REPAIR

11gR1

24­Dec­2007

­

DBMS_REPUTIL

11gR1

20­Sep­2007

­

DBMS_RESOURCE_MANAGER

11gR1

25­Dec­2007

­

DBMS_RESOURCE_MANAGER_PRIVS

11gR1

24­Nov­2007

­

DBMS_RESULT_CACHE

11gR1

02­Dec­2007

­

DBMS_RESUMABLE

11gR1

24­Nov­2007

­

DBMS_RLS

11gR1

17­May­2008

­

DBMS_ROWID

11gR1

26­Nov­2007

­

DBMS_SCHEDULER

11gR1

19­May­2008

­

DBMS_SCHEMA_COPY

10gR2

06­May­2006

Dropped from 11.1.0.6

DBMS_SERVER_ALERT

11gR1

07­Apr­2008

­

DBMS_SERVER_TRACE

11gR1

30­Mar­2008

­

DBMS_SERVICE

11gR1

22­Dec­2007

­

DBMS_SESSION

11gR1

14­Sep­2007

­

DBMS_SESSION_STATE

11gR1

14­Dec­2007

­

DBMS_SHARED_POOL

11gR1

20­Nov­2007

­

DBMS_SNAPSHOT

11gR1

07­Sep­2007

­

DBMS_SPACE

11gR1

23­Aug­2007

­

DBMS_SPACE_ADMIN

11gR1

23­Aug­2007

­

Oracle Complete PLSQL Reference

181

DBMS_SPM

11gR1

13­Sep­2007

­

DBMS_SQL

11gR1

14­Apr­2008

­

DBMS_SQLDIAG

11gR1

28­Sep­2007

­

DBMS_SQLHASH

11gR1

29­Aug­2007

­

DBMS_SQLJTYPE

11gR1

19­Aug­2007

­

DBMS_SQLPA

11gR1

13­Sep­2007

­

DBMS_SQLPLUS_SCRIPT

11gR1

06­Dec­2007

­

DBMS_SQLTUNE

11gR1

02­Dec­2008

DBMS_STAT_FUNCS

11gR1

01­Apr­2008

DBMS_STATS

11gR1

27­Nov­2008

DBMS_STORAGE_MAP

11gR1

19­Aug­2007

­

DBMS_STREAMS

11gR1

01­Apr­2008

­

DBMS_STREAMS_ADM

11gR1

01­Apr­2008

­

DBMS_STREAMS_AUTH

11gR1

18­Dec­2007

­

DBMS_SUPPORT

11gR1

29­Jan­2008

­

DBMS_SYSTEM

11gR1

28­Mar­2008

­

DBMS_TDB

11gR1

24­Dec­2007

­

DBMS_TRACE

11gR1

29­Jan­2008

­

DBMS_TRANSACTION

11gR1

03­Nov­2007

­

DBMS_TRANSFORM

11gR1

04­Apr­2008

­

DBMS_TTS

11gR1

07­Apr­2008

­

DBMS_TYPES

11gR1

29­Jul­2007

­

DBMS_UNDO_ADV

11gR1

19­Aug­2007

­

DBMS_UTILITY

11gR1

04­Nov­2008

DBMS_WARNING

11gR1

06­Jan­2008

­

DBMS_WARNING_INTERNAL

11gR1

15­Jul­2007

­

DBMS_WLM

11gR1

19­Sep­2007

­

DBMS_WM Synonym

10gR2

17­Dec­2005

­

DBMS_WORKLOAD_CAPTURE

11gR1

07­Sep­2007

­

DBMS_WORKLOAD_REPLAY

11gR1

07­Sep­2007

­

DBMS_WORKLOAD_REPOSITORY

11gR1

17­Aug­2007

­

DBMS_XA

11gR1

13­Aug­2007

­

DBMS_XDBUTIL_INT

11gR1

26­Dec­2007

­

DBMS_XMLGEN

11gR1

29­Mar­2008

­

DBMS_XPLAN

11gR1

28­Apr­2008

­

DBMS_ZHELP

11gR1

13­Jul­2007

­

DBMS_ZHELP_IR

11gR1

13­Jul­2007

­

DBV (database verify)

11gR1

05­Oct­2007

­

DCL Statements

11gR1

29­Jul­2007

­

DDL Event Triggers

11gR1

18­Mar­2008

­

Deadlocks

11gR1

08­Dec­2007

­

DECODE Function

11gR1

15­Aug­2007

­

Deferrable Constraints

11gR1

21­Jun­2008

­ 

Delete Statement

11gR1

12­Aug­2007

­

Descending Indexes

11gR1

03­Nov­2008

DICOM

11gR1

24­Sep­2008

Dimensions

11gR1

02­Dec­2008

Directories

11gR1

29­Jul­2007

­

Disassociate Statistics

11gR1

03­Jan­2008

­

DIUTIL

11gR1

11­Jul­2007

­

DML Statements

11gR1

07­Jul­2007

­

Dumping Oracle

11gR1

10­Apr­2008

­

Dynamic Performance Views

11gR1

28­Aug­2008

­

11.5.10

29­Sep­2007

­

Editions

11gR1

11­Aug­2007

­

Encrypted Tablespaces

11gR1

30­Sep­2007

­

E­Business Suite

Oracle Complete PLSQL Reference

182

­

­

Environment Variables

11gR1

30­Mar­2008

­

Errors

11gR1

30­Jul­2007

­

Events

11gR1

04­Sep­2008

­

Exception Handling

11gR1

01­Dec­2008

Excluded Nodes

11gR1

27­Sep­2008

­

Exists

11gR1

08­Jul­2007

­

Explain Plan

11gR1

16­Aug­2007

­

Export

11gR1

27­Oct­2007

­

10g

28­Apr­2005

­

External Tables

11gR1

10­Feb­2008

­

Files Of Interest

11gR1

25­Sep­2008

­

Fine Grained Access Control (FGAC)

11gR1

17­May­2008

­

Fine Grained Access Control Demo

11gR1

17­Nov­2008

Fine Grained Auditing (FGA)

11gR1

24­Dec­2007

­

Flashback

11gR1

14­Aug­2007

­

Flashback Archive

11gR1

15­Oct­2007

­

Flashback Database

11gR1

14­Aug­2007

­

Flashback Drop

11gR1

14­Aug­2007

­

Flashback Query

11gR1

14­Aug­2007

­

Flashback Table

11gR1

14­Aug­2007

­

Flashback Transaction

11gR1

14­Aug­2007

­

Flashback Version

11gR1

14­Aug­2007

­

FOLLOWS Clause (Triggers)

11gR1

12­Aug­2007

­

FOR UPDATE

11gR1

07­Jul­2007

­

FORALL

11gR1

17­Aug­2008

­

Foreign Key Constraint

11gR1

29­Feb­2008

­

10g

24­Jan­2005

­

Function Based Indexes

11gR1

03­Nov­2008

Functions: Deterministic

11gR1

27­Sep­2008

­

Functions: Miscellaneous

11gR1

19­Aug­2007

­

Functions: User Defined

11gR1

10­Jan­2008

­

Fusion MiddleWare Application Server

10.1.2.0.2

02­Jan­2007

­

Fusion MiddleWare Application Server

10.1.3.0.0

02­Jan­2007

­

Global Hints

10gR2

22­Aug­2006

­

Global Partitioned Indexes

11gR1

25­Nov­2007

­

Global Temporary Tables

11gR1

01­Nov­2007

­

Globalization Toolkit

11gR1

10­Oct­2007

­

10.2.0.4

01­Jan­2008

­

GROUP BY Clauses

11gR1

22­Oct­2007

­

GROUP ID

11gR1

22­Oct­2007

­

GROUPING SETS

11gR1

22­Oct­2007

­

Guaranteed Restore Point

11gR1

29­Jul­2007

­

GV$ Views

11gR1

01­Nov­2007

­

Hash Partitioning

11gR1

25­Nov­2007

­

HAVING Clauses

11gR1

22­Oct­2007

­

Heap Tables

11gR1

26­Nov­2008

Hints

10gR2

08­Apr­2008

­

Histograms

11gR1

02­Mar­2008

­

Host Environment

11gR1

02­Mar­2008

­

HTP

11gR1

30­Mar­2008

­

IF Statements

11gR1

06­Aug­2007

­

Import

11gR1

27­Oct­2007

­

Indexes

11gR1

03­Nov­2008

Index Organized Tables (IOT)

11gR1

09­Nov­2007

Init SID Dot Ora

11gR1

13­Nov­2008

Inline Views

11gR1

02­Mar­2008

Expression Filtering

FORMs

Grid Control

Oracle Complete PLSQL Reference

183

­ ­

Insert Statements

11gR1

29­Oct­2007

Instead­Of Triggers

11gR1

08­Nov­2008

Instring Function

11gR1

27­Jul­2007

­

Intermedia Audio

11gR1

25­Aug­2008

­

Intermedia Video

11gR1

25­Aug­2008

­

Interval

11gR1

20­Dec­2007

­

Interval Partitioning

11gR1

25­Nov­2007

­

Invisible Indexes

11gR1

03­Nov­2008

Invited Nodes

11gR1

27­Sep­2008

­

IS NOT OF TYPE

11gR1

17­Aug­2008

­

IS OF ONLY

11gR1

17­Aug­2008

­

IS OF TYPE

11gR1

17­Aug­2008

­

Java Functions

11gR1

20­Mar­2008

­

Joins

11gR1

16­Aug­2008

­

Keep Pool

11gR1

15­Jul­2007

­

Killing Sessions

11gR1

08­Feb­2008

­

Large Objects

11gR1

18­Oct­2008

­

LCR$_XML_SCHEMA

11gR1

18­Oct­2008

­

Licensing

10gR2

30­Sep­2006

­

Licensing

11gR1

08­Feb­2008

­

Linux Installation for Oracle RDBMS

10gR2

16­Jan­2008

­

Linux Installation for Oracle RDBMS

11gR1

16­Jan­2008

­

List Partitioning

11gR1

25­Nov­2007

­

Listener

11gR1

03­Mar­2008

­

LOB Compression

11gR1

29­Jul­2007

­

LOBs

11gR1

18­Oct­2008

­

Local Partitioned Indexes

11gR1

25­Nov­2007

­

Locks

11gR1

09­Feb­2008

­

Log Files

11gR1

27­Nov­2007

­

LONG To CLOB

11gR1

09­Feb­2008

­

Loops

11gR1

19­Dec­2007

­

LT Built­in Package

10gR2

17­Dec­2005

­

Materialized Views

11gR1

06­Jun­2008

­

Merge Statement

11gR1

12­Aug­2007

­

­

24­Apr­2007

­

Microsoft SQL Server 2005 Comparison Microsoft Vista Enterprise and Oracle

­

­

21­Apr­2007

­

10g

09­Dec­2006

­

Multimedia Audio

11gR1

25­Aug­2008

­

Multimedia Video

11gR1

25­Aug­2008

­

Multiset

11gR1

21­Jul­2007

­

Multiversion Concurrency Control (MVCC) 

11gR1

11­Nov­2007

­

Native Compilation

11gR1

09­Aug­2007

­

Native Dynamic SQL (NDS)

11gR1

20­Feb­2008

­

Nested Loops

11gR1

24­Dec­2007

­

Nested Tables

11gR1

02­Dec­2008

Nested Table Constraints

11gR1

23­Nov­2007

­

NetApp Filer Head

11gR1

10­Oct­2008

­

Net Services

11gR1

13­Nov­2008

Model Clause

Network Appliance Filer Management

­

16­Jan­2007

­

NID (change internal database identifier)

11gR1

05­Oct­2007

­

No Segment Indexes

11gR1

03­Nov­2008

NOCOPY

11gR1

14­Sep­2007

­

­

28­May­2007

­

NOWAIT

11gR1

07­Jul­2007

­

Numeric Functions

11gR1

16­Oct­2008

­

NULL

11gR1

14­Sep­2007

­

Normalization

Oracle Complete PLSQL Reference

184

NULL Pruning

11gR1

04­Dec­2007

­

Object Privileges

11gR1

24­Dec­2007

­

10g

17­Nov­2004

­

Object Tables: See Nested Tables and Varrays

11gR1

20­Sep­2008

­

OBJECT_ID

11gR1

25­Aug­2007

­

Operators: Built­in

11gR1

16­Aug­2008

­

Operators: User Defined

11gR1

19­Sep­2007

­

ORA_HASH

11gR1

13­Jul­2007

­

ORA_NAME_LIST_T

11gR1

22­Dec­2007

­

ORA_ROWSCN

11gR1

25­Aug­2007

­

ORADEBUG

11gR1

25­Sep­2008

­

ORADIM

10gR2

23­Nov­2005

­

ORAPWD

11gR1

13­Dec­2007

­

ORDER BY Clause

11gR1

22­Oct­2007

­

Outlines

11gR1

30­Mar­2008

­

OUTLN_EDIT_PKG

11gR1

30­Mar­2008

­

OUTLN_PKG

11gR1

30­Mar­2008

­

OWA

11gR1

18­Dec­2007

­

OWA_CUSTOM

11gR1

15­Sep­2007

­

OWA_CX

11gR1

15­Sep­2007

­

OWA_OPT_LOCK

11gR1

15­Sep­2007

­

OWA_SEC

11gR1

15­Sep­2007

­

OWA_TEXT

11gR1

15­Sep­2007

­

OWA_UTIL

11gR1

09­Apr­2008

­

Packages: User Defined

11gR1

17­Oct­2008

­

Parent Correlation Name

11gR1

06­Aug­2007

­

Partitioning (tables and indexes)

11gR1

25­Nov­2007

­

Partitioning by Reference

11gR1

25­Nov­2007

­

Partition by System

11gR1

29­Dec­2007

­

Partitioning Elimination Demo

11gR1

25­Nov­2007

­

Partitioning Pruning Demo

11gR1

25­Nov­2007

­

Password File

11gR1

19­Nov­2008

Pipelined Table Functions

11gR1

17­Dec­2007

­

Pivot

11gR1

02­Oct­2007

­

PLSHPROF

11gR1

23­Aug­2007

­

PLSQL_CCFLAGS

11gR1

25­Nov­2007

­

PL/Scope

11gR1

02­Feb­2008

­

PL/SQL Object Settings

11gR1

09­Aug­2007

­

PL/SQL Warnings

11gR1

16­Jan­2008

­

PRAGMAS

11gR1

27­Jan­2008

­

PRAGMA Autonomous_Transaction

11gR1

30­Jan­2008

­

PRAGMA Exception_Init

11gR1

02­Oct­2007

­

PRAGMA Inline

11gR1

02­Oct­2007

­

Object­Relational Views

PRAGMA Serially Reusable

11gR1

02­Oct­2007

­

  Primary   Key Constraint

11gR1

25­Nov­2007

­

Procedures

11gR1

17­Dec­2007

­

Product User Profiles

11gR1

17­Oct­2007

­

Profiles

11gR1

20­Dec­2007

­

Protocol.ora

11gR1

27­Sep­2008

Deprecated See: SQLNET.ORA

Pseudo Columns

11gR1

25­Aug­2007

­

Public Synonyms

11gR1

21­Jul­2007

­

Purge Recyclebin

11gR1

14­Aug­2007

­

Purge Table

11gR1

14­Sep­2007

­

Quote Delimiters

11gR1

14­Sep­2007

­

RAC

11gR1

15­Oct­2008

­

RAID

11gR1

09­Feb­2008

­

Oracle Complete PLSQL Reference

185

Range Partitioning

11gR1

25­Nov­2007

­

Rank

11gR1

02­Mar­2008

­

RDA

10gR2

05­Oct­2006

­

Real Application Clusters

11gR1

15­Oct­2008

­

Recycle Bin

11gR1

30­Dec­2007

­

Recycle Pool

11gR1

15­Jul­2007

­

Redo

11gR1

01­Oct­2007

­

Ref Cursors

11gR1

05­Dec­2007

­

Referential Constraint

11gR1

29­Feb­2008

­

Referential Partition

11gR1

25­Nov­2007

­

Regular Expressions

11gR1

09­Feb­2008

­

Remote Diagnostic Agent

10gR2

05­Oct­2006

­

Replace Built­in Function

11gR1

07­Aug­2007

­

Restore Point

11gR1

29­Jul­2007

­

Result Cache (SQL)

11gR1

02­Dec­2007

­

Result Cache (PL/SQL)

11gR1

02­Dec­2007

­

Resumable Transactions_

11gR1

03­Nov­2007

­

Reverse Key Indexes

11gR1

03­Nov­2008

Rewrite Equivalence

11gR1

11­Aug­2007

­

RMAN

10gR2

26­Apr­2006

incomplete

RMAN Demo

11gR1

20­Oct­2008

­

Roles

11gR1

03­Oct­2007

­

Rollback

11gR1

07­Jul­2007

­

Rollup

11gR1

06­Oct­2007

­

ROWDEPENDENCIES

11gR1

25­Aug­2007

­

ROWID

11gR1

25­Aug­2007

­

Row Level Security

11gR1

17­May­2008

­

ROWNUM

11gR1

25­Aug­2007

­

­

16­Apr­2004

Deprecated

Sample Clause

11gR1

29­Oct­2008

­

Savepoint

11gR1

07­Jul­2007

­

Schema

11gR1

08­Jul­2007

­

SecureFiles

11gR1

19­Jul­2008

­

Security

11gR1

27­May­2008

­

Segments

11gR1

18­Oct­2008

­

Select Statement

11gR1

29­Oct­2008

­

Select Into Statement

11gR1

29­Oct­2008

­

Sequences

11gR1

11­Aug­2007

­

Services

11gR1

22­Dec­2007

­

Sessions

11gR1

11­Sep­2008

­

Set Operators

11gR1

19­Sep­2007

­

SET TRANSACTION

11gR1

15­Dec­2007

­

SHOW

11gR1

24­Dec­2007

­

SKIP LOCKED

11gR1

07­Jul­2007

­

SLEEP

11gR1

25­Aug­2007

­

Snapshots

11gR1

21­Nov­2007

­

Sorted Hash Clusters

11gR1

20­Jul­2007

­

Soundex

11gR1

14­Sep­2007

­

SPFile

11gR1

13­Nov­2008

SQL Injection

10gR2

05­Mar­2007

­

SQL*Loader

10gR2

17­Dec­2007

­

SQL*Plus

11gR1

16­Dec­2007

­

SQLNET.ORA

11gR1

27­Sep­2008

­

Standard

11gR1

01­Dec­2008

Starting & Stopping The Database

11gR1

05­Apr­2008

Startup Parameters

11gR1

13­Nov­2008

Rule Based Optimizer (RBO)

Oracle Complete PLSQL Reference

186

­

Stored Outlines

11gR1

30­Mar­2008

­

Stored Procedures

11gR1

17­Dec­2007

­

­

19­Oct­2006

­

Streams Demo 1

10gR2

07­Jun­2007

­

Streams Demo 2

10gR2

07­Jun­2007

­

Streams Demo 3

10gR2

07­Jun­2007

­

String Functions

11gR1

16­Oct­2008

­

Subqueries

11gR1

08­Jul­2007

­

Substring Function

11gR1

27­Jul­2007

­

­

26­Jan­2007

­

Synonyms

11gR1

21­Jul­2007

­

SYS_CONTEXT Built­in Function

11gR1

19­Aug­2007

­

SYS_GUID

11gR1

09­Dec­2006

­

SYS_OP_COMBINED_HASH

11gR1

18­Aug­2008

­

SYS_OP_DESCEND

11gR1

25­Aug­2007

­

SYS_OP_DISTINCT

11gR1

25­Aug­2007

­

SYS_OP_GUID

11gR1

25­Aug­2007

­

SYS_OP_LBID

11gR1

25­Aug­2007

­

SYS_OP_MAP_NONNULL

11gR1

25­Aug­2007

­

SYS_OP_RAWTONUM

11gR1

25­Aug­2007

­

SYS_OP_RPB

11gR1

25­Aug­2007

­

SYS_OP_TOSETID

11gR1

25­Aug­2007

­

SYS_TYPEID

11gR1

25­Aug­2007

­

  System   

11gR1

20­Sep­2008

­

  System Events   

11gR1

18­Mar­2008

­

System Event Triggers

11gR1

06­Jan­2008

­

  System Privileges   

11gR1

08­Jan­2008

­

  System Statistics   

11gR1

08­Apr­2008

­

Table Collection Expression

11gR1

30­Nov­2008

Tables

11gR1

26­Nov­2008

Table Triggers

11gR1

13­Feb­2008

­

Tablespaces

11gR1

23­Oct­2008

­

Tablespace Groups

11gR1

22­Nov­2007

­

Timestamp

11gR1

20­Dec­2007

­

Time Zones

11gR1

20­Dec­2007

­

TKPROF

11gR1

04­Sep­2008

­

Total Recall

11gR1

09­Aug­2007

­

Trace File Identifier

11gR1

19­Feb­2008

­

Tracing

11gR1

04­Sep­2008

­

Transaction Backout

11gR1

16­Oct­2007

­

Transactions

11gR1

15­Dec­2007

­

Translate Built­in Function

11gR1

07­Aug­2007

­

Transparent Data Encryption

11gR1

29­Oct­2007

­

Transportable Tablespaces

11gR1

21­Jun­2008

­

Truncate (Tables & Partitions)

11gR1

30­Jul­2007

­

Tuning

11gR1

15­Aug­2008

­

Types

11gR1

02­Dec­2008

Undo Tablespace

11gR1

20­Nov­2008

Undocumented Oracle

11gR1

17­Aug­2008

­

­

09­Apr­2008

­

Unique Constraint

11gR1

25­Nov­2007

­

Unpivot

11gR1

02­Oct­2007

­

Update Statement

11gR1

02­Nov­2007

­

USERENV

11gR1

25­Aug­2007

See SYS_CONTEXT

Users

11gR1

22­Apr­2008

­

USER_LOCK

11gR1

27­Jul­2007

­

Storage

Sybase ASE 15.0.1 Comparison

UNIX / vi

Oracle Complete PLSQL Reference

187

Utilities

11gR1

19­Nov­2008

UTL_COLL

11gR1

29­Jul­2007

­

UTL_COMPRESS

11gR1

29­Jul­2007

­

UTL_ENCODE

11gR1

10­Oct­2007

­

UTL_FILE

11gR1

18­Mar­2008

­

UTL_GDK

11gR1

10­Oct­2007

­

UTL_HTTP

11gR1

23­Jan­2008

­

UTL_I18N

11gR1

27­Jul­2007

­

UTL_INADDR

11gR1

07­Jul­2007

­

UTL_LMS

11gR1

07­Jul­2007

­

UTL_MAIL

11gR1

11­Aug­2007

­

UTL_MATCH

11gR1

10­Oct­2007

­

UTL_RAW

11gR1

10­Oct­2007

­

UTL_RECOMP

11gR1

30­Jul­2007

­

UTL_REF

11gR1

31­Mar­2008

­

UTL_SMTP

11gR1

18­Dec­2007

Deprecated: See UTL_MAIL

UTL_SPADV

11gR1

18­Mar­2008

­

UTL_TCP

11gR1

12­Aug­2007

­

UTL_URL

11gR1

11­Aug­2007

­

UTL_XML

11gR1

01­Apr­2008

­

Variables

11gR1

21­Aug­2007

­

VARRAYS

11gR1

01­Apr­2008

­

VERSIONS BETWEEN

11gR1

25­Aug­2007

­

Views

11gR1

26­Oct­2007

­

Virtual Columns

11gR1

18­Oct­2007

­

Virtual Column Partitioning

11gR1

25­Nov­2007

­

Virtual Indexes

11gR1

03­Nov­2008

Virtual Private Database

11gR1

17­May­2008

­

V$ Views

11gR1

01­Nov­2007

­

WAIT

11gR1

07­Jul­2007

­

Where Clause

11gR1

29­Jul­2007

­

Wildcards

11gR1

14­Sep­2007

­

WITH Clause

11gR1

10­Feb­2008

­

WM_CONCAT

11gR1

03­Dec­2007

­

Workspace Manager

10gR2

17­Dec­2005

­

WPG_DOCLOAD

11gR1

17­Dec­2007

­

Wrap

11gR1

05­Oct­2007

­

Write CLOB to file

11gR1

01­Feb­2008

­

XML Functions

11gR1

14­Sep­2007

­

XMLQuery

11gR1

27­Jan­2008

­

XMLTable

11gR1

26­Jan­2008

­

XMLTYPE

11gR1

14­Jul­2007

­

XML Tables

11gR1

26­Jan­2008

­

XML SCHEMA_NAME_PRESENT

11gR1

17­Jun­2008

­

Oracle Complete PLSQL Reference

188

3. built in PKG Oracle Built­in Packages Version 11.1

Oracle Complete PLSQL Reference

189

Common Name 

Owner 

Undocumented

SYS

Baseline Statistics

DBSNMP

Undocumented

Package Name  BLAST_CUR BSLN BSLN_INTERNAL

ORDSYS CARTRIDGE

Context Administration

Last Modified  14­Dec­2007 ­ ­

-

CTX_ADM

*

Context

CTX_CATSEARCH

­

Context

CTX_CLS

*

Context

CTX_CONTAINS

Context

CTX_DDL

24­Dec­2007

Context

CTX_DOC

*

Context

CTXSYS CTX_MATCHES

­

­

Context

CTX_OUTPUT

*

Context

CTX_QUERY

*

Context

CTX_REPORT

*

CTX_THES

*

Context

CTX_ULEXER

*

Context

CTX_XPCONTAINS

­

CWM2_OLAP_INSTALLER

-

Context Thesaurus

Validates OLAP Installation

SYS 

Export Support for SQL Tuning Base

DBMSHSXP

Internal

Replication Object Generator

DBMSOBJG

08­Jul­2007

Generate Partitioned Object Storage

DBMSOBJG2

Internal

DBMSOBJGWRAPPER

Internal

Generate DDL

DBMSOBJG_DP

Internal

Undocumented

DBMSZEXP_SYSPKGGRNT

Internal

SYS 

Generate and rollback DDL

ADDM

SYS

DBMS_ADDM

16­Nov­2007

Query Equivalence

SYS

DBMS_ADVANCED_REWRITE

11­Aug­2007

ADDM

SYS

DBMS_ADVISOR

01­Feb­2008

Asynchronous Messaging

SYS

DBMS_ALERT

08­Jul­2007

Move OLAP Catalog

SYS

DBMS_AMD

08­Jul­2007

Contexts / Security

SYS

DBMS_APPCTX

Internal

Register Code For Tracking

SYS

DBMS_APPLICATION_INFO

06-Jan2008

Streams Apply Process

DBMS_APPLY_ADM

Streams Apply Process Internal Processes Streams Apply Process Error Handling

SYS

Streams Internal ­ New in 11g Streams Internal SYS

Advanced Queuing Interface Advanced Queuing Administrator Used by DBMS_AQADM to manage Streams AQ

Internal

DBMS_APPLY_ERROR

Internal

DBMS_APPLY_POSITION

Internal

DBMS_APPLY_PROCESS

Internal

DBMS_AQ

05­Nov­2007

DBMS_AQADM

06­Apr­2008

DBMS_AQADM_SYS

Advanced Queuing

DBMS_AQADM_SYSCALLS

Email & HTTP Asynchronous Notification 

DBMS_AQELM

Secure Access To JMS Interfaces

DBMS_AQIN

JMS Interface

DBMS_AQJMS

JMS Interface Internal

12­Dec­2007

DBMS_APPLY_ADM_INTERNAL

DBMS_AQJMS_INTERNAL

Internal ­ 08­Oct­2007 * ­ Internal

Advanced Queuing

DBMS_AQ_BQVIEW

­

Advanced Queuing

DBMS_AQ_EXP_CMT_TIME_TABLES

­

Advanced Queuing

DBMS_AQ_EXP_HISTORY_TABLES

­

DBMS_AQ_EXP_INDEX_TABLES

­

Advanced Queuing Advanced Queuing Oracle Complete PLSQL Reference

190

Oracle Complete PLSQL Reference

191

 Loop Examples – Mohamed gamal course SQL> SQL> SQL> -- basic loop SQL> SQL> SQL> select * from dept; DEPTNO DNAME LOC ---------- -------------- ------------10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON SQL> SQL> SQL> set serveroutput on; SQL> SQL> SQL> SQL> create or replace procedure rep1 2 3 is 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 8 begin 9 select deptno , dnaem , loc 10 into v1 , v2 , v3 11 from dept; 12 13 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3) 14 15 end 16 ; 17 / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------15/1 PLS-00103: Encountered the symbol "END" when expecting one of the following: := . ( % ; The symbol ";" was substituted for "END" to continue. Oracle Complete PLSQL Reference

192

SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 select deptno , dnaem , loc 8 into v1 , v2 , v3 9 from dept; 10 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 11 end 12* ; 13 / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------7/1 PL/SQL: SQL Statement ignored 7/17 PL/SQL: ORA-00904: "DNAEM": invalid identifier SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 select deptno , dname , loc 8 into v1 , v2 , v3 9 from dept; 10 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 11 end 12* ; SQL> / Procedure created. SQL> exex rep1; SP2-0042: unknown command "exex rep1" - rest of line ignored. SQL> exec rep1; BEGIN rep1; END; * ERROR at line 1: Oracle Complete PLSQL Reference

193

ORA-01422: exact fetch returns more than requested number of rows ORA-06512: at "SCOTT.REP1", line 7 ORA-06512: at line 1 SQL> SQL> SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 begin 8 select deptno , dname , loc 9 into v1 , v2 , v3 10 from dept 11 where deptno = v_counter; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 13 end 14* ; 15 / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 begin 8 LOOP 9 select deptno , dname , loc 10 into v1 , v2 , v3 11 from dept 12 where deptno = v_counter; 13 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 14 v_counter := v_counter + 10 ; 15 exit when v_counter = 50; 16 end loop; Oracle Complete PLSQL Reference

194

17 end 18* ; 19 / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 vmax number(5); 8 begin 9 select max(deptno) into vmax from dept; 10 LOOP 11 select deptno , dname , loc 12 into v1 , v2 , v3 13 from dept 14 where deptno = v_counter; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 16 v_counter := v_counter + 10 ; 17 exit when v_counter = vmax+1; 18 end loop; 19 end 20* ; 21 / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON BEGIN rep1; END; * ERROR at line 1: ORA-01403: no data found ORA-06512: at "SCOTT.REP1", line 11 Oracle Complete PLSQL Reference

195

ORA-06512: at line 1 SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 vmax number(5); 8 begin 9 select max(deptno) into vmax from dept; 10 LOOP 11 select deptno , dname , loc 12 into v1 , v2 , v3 13 from dept 14 where deptno = v_counter; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 16 v_counter := v_counter + 10 ; 17 exit when v_counter > vmax; 18 end loop; 19 end 20* ; SQL> / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PL/SQL procedure successfully completed. SQL> select * from dept; DEPTNO DNAME LOC ---------- -------------- ------------10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON SQL> insert into dept values(50,'a','a'); 1 row created. SQL> ed; Oracle Complete PLSQL Reference

196

Wrote file afiedt.buf 1* insert into dept values(60,'a','a') SQL> / 1 row created. SQL> ed; Wrote file afiedt.buf 1* insert into dept values(70,'a','a') SQL> / 1 row created. SQL> commit; Commit complete. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a a 60 a a 70 a a PL/SQL procedure successfully completed. SQL> update emp set dname = null where deptno = 50; update emp set dname = null where deptno = 50 * ERROR at line 1: ORA-00904: "DNAME": invalid identifier SQL> ed; Wrote file afiedt.buf 1* update dept set dname = null where deptno = 50 SQL> / 1 row updated. SQL> commit; Commit complete. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS Oracle Complete PLSQL Reference

197

30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a 60 a a 70 a a PL/SQL procedure successfully completed. SQL> create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 vmax number(5); 8 begin 9 select max(deptno) into vmax from dept; 10 for i in 1..7 loop 11 select deptno , dname , loc 12 into v1 , v2 , v3 13 from dept 14 where deptno = v_counter; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 16 v_counter := v_counter + 10 ; 17 18 end loop; 19 end 20 ; 21 / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a 60 a a 70 a a PL/SQL procedure successfully completed. SQL> select * from dept; DEPTNO DNAME LOC ---------- -------------- ------------10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a Oracle Complete PLSQL Reference

198

60 a 70 a

a a

7 rows selected. SQL> create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 x number(5); 8 begin 9 10 select count(*) into x from dept; 11 for i in 1..x loop 12 select deptno , dname , loc 13 into v1 , v2 , v3 14 from dept 15 where deptno = v_counter; 16 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 17 v_counter := v_counter + 10 ; 18 19 end loop; 20 end 21 ; 22 / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a 60 a a 70 a a PL/SQL procedure successfully completed. SQL> delete from dept where deptno > 50; 2 rows deleted. SQL> commit; Commit complete. SQL> select * from dept; DEPTNO DNAME Oracle Complete PLSQL Reference

LOC 199

---------- -------------- ------------10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a PL/SQL procedure successfully completed. SQL> select count(*) from emp; COUNT(*) ---------14 SQL> select count(*) from dept; COUNT(*) ---------5 SQL> create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 begin 8 while v_counter > 50 loop 9 select deptno , dname , loc 10 into v1 , v2 , v3 11 from dept 12 where deptno = v_counter; 13 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 14 v_counter := v_counter + 10 ; 15 16 end loop; 17 end 18 ; 19 / Procedure created. SQL> exec rep1; Oracle Complete PLSQL Reference

200

PL/SQL procedure successfully completed. SQL> set serveroutput on; SQL> SQL> exec rep1; PL/SQL procedure successfully completed. SQL> exec rep1; PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 begin 8 while v_counter < 50 loop 9 select deptno , dname , loc 10 into v1 , v2 , v3 11 from dept 12 where deptno = v_counter; 13 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 14 v_counter := v_counter + 10 ; 15 end loop; 16 end 17* ; 18 / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 2 3 4 5

create or replace procedure rep1 is v1 number(5); v2 varchar2(20); v3 varchar2(20);

Oracle Complete PLSQL Reference

201

6 v_counter number(5) := 10; 7 x number(5); 8 begin 9 select max(deptno) into x from dept 10 while v_counter < x loop 11 select deptno , dname , loc 12 into v1 , v2 , v3 13 from dept 14 where deptno = v_counter; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 16 v_counter := v_counter + 10 ; 17 end loop; 18 end 19* ; SQL> / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------9/1 PL/SQL: SQL Statement ignored 10/7 PL/SQL: ORA-00933: SQL command not properly ended 17/5 PLS-00113: END identifier 'LOOP' must match 'REP1' at line 1, column 11 18/1 PLS-00103: Encountered the symbol "END" SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 x number(5); 8 begin 9 select max(deptno) into x from dept; 10 while v_counter < x loop 11 select deptno , dname , loc 12 into v1 , v2 , v3 13 from dept 14 where deptno = v_counter; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 16 v_counter := v_counter + 10 ; 17 end loop; 18* end; SQL> / Oracle Complete PLSQL Reference

202

Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PL/SQL procedure successfully completed. SQL> select * from dept; DEPTNO DNAME LOC ---------- -------------- ------------10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a SQL> create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 v_counter number(5) := 10; 7 x number(5); 8 begin 9 select max(deptno) into x from dept; 10 while v_counter < x loop 11 select deptno , dname , loc 12 into v1 , v2 , v3 13 from dept 14 where deptno = v_counter; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 16 v_counter := v_counter + 10 ; 17 end loop; 18 end; 19 / Procedure created. SQL> ed; Wrote file afiedt.buf 1 2 3 4 5 6 7

create or replace procedure rep1 is v1 number(5); v2 varchar2(20); v3 varchar2(20); v_counter number(5) := 10; x number(5);

Oracle Complete PLSQL Reference

203

8 begin 9 select max(deptno) into x from dept; 10 while v_counter / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a PL/SQL procedure successfully completed. SQL> insert into dept values (60,'b','b'); 1 row created. SQL> commit; Commit complete. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a 60 b b PL/SQL procedure successfully completed. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------- ---------- ---------- ---------7369 SMITH CLERK 7902 17/12/80 800 20 7499 ALLEN SALESMAN 7698 20/02/81 1600 300 30 7521 WARD SALESMAN 7698 22/02/81 1250 500 30 7566 JONES MANAGER 7839 02/04/81 2975 20 7654 MARTIN SALESMAN 7698 28/09/81 1250 1400 30 7698 BLAKE MANAGER 7839 01/05/81 2850 30 Oracle Complete PLSQL Reference

204

7782 CLARK MANAGER 7839 09/06/81 2450 7788 SCOTT ANALYST 7566 19/04/87 3000 7839 KING PRESIDENT 17/11/81 5000 7844 TURNER SALESMAN 7698 08/09/81 1500 7876 ADAMS CLERK 7788 23/05/87 1100 7900 JAMES CLERK 7698 03/12/81 950 7902 FORD ANALYST 7566 03/12/81 3000 7934 MILLER CLERK 7782 23/01/82 1300 14 rows selected. SQL> create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 7 begin 8 9 for i in 1..14 loop 10 11 select empno , ename , job 12 into v1 , v2 , v3 13 from emp; 14 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 15 16 end loop; 17 end; 18 / Procedure created. SQL> exec rep1; BEGIN rep1; END; * ERROR at line 1: ORA-01422: exact fetch returns more than requested number of rows ORA-06512: at "SCOTT.REP1", line 11 ORA-06512: at line 1 SQL> select empno , ename , job from emp; EMPNO ENAME JOB ---------- ---------- --------7369 SMITH CLERK 7499 ALLEN SALESMAN 7521 WARD SALESMAN 7566 JONES MANAGER 7654 MARTIN SALESMAN 7698 BLAKE MANAGER Oracle Complete PLSQL Reference

205

10 20 10 0 30 20 30 20 10

7782 CLARK MANAGER 7788 SCOTT ANALYST 7839 KING PRESIDENT 7844 TURNER SALESMAN 7876 ADAMS CLERK 7900 JAMES CLERK 7902 FORD ANALYST 7934 MILLER CLERK 14 rows selected. SQL> create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 7 begin 8 9 for i in (select empno , ename , job from emp) loop 10 select empno , ename , job 11 into v1 , v2 , v3 12 from emp; 13 dbms_output.put_line(I.v1 || ' ' || I.v2 || ' ' || I.v3); 14 15 end loop; 16 end 17 ; 18 / Warning: Procedure created with compilation errors. SQL> SHOW ERR; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------13/1 PL/SQL: Statement ignored 13/24 PLS-00302: component 'V1' must be declared SQL> ED; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 for i in (select empno , ename , job from emp) loop 8 select empno , ename , job 9 into v1 , v2 , v3 10 from emp; Oracle Complete PLSQL Reference

206

11 dbms_output.put_line(i.v1 || ' ' || i.v2 || ' ' || i.v3); 12 end loop; 13 end 14* ; 15 / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------11/1 PL/SQL: Statement ignored 11/24 PLS-00302: component 'V1' must be declared SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 for i in (select empno , ename , job from emp) loop 8 select empno , ename , job 9 into i.v1 , i.v2 , i.v3 10 from emp; 11 dbms_output.put_line(i.v1 || ' ' || i.v2 || ' ' || i.v3); 12 end loop; 13 end 14* ; SQL> / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------8/1 PL/SQL: SQL Statement ignored 9/8 PLS-00302: component 'V1' must be declared 9/25 PL/SQL: ORA-00904: : invalid identifier 11/1 PL/SQL: Statement ignored 11/24 PLS-00302: component 'V1' must be declared SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); Oracle Complete PLSQL Reference

207

4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 for i in (select empno , ename , job from emp) loop 8 select empno , ename , job 9 into v1,v2,v3 10 from emp; 11 dbms_output.put_line(i.v1 || ' ' || i.v2 || ' ' || i.v3); 12 end loop; 13 end 14* ; SQL> / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------11/1 PL/SQL: Statement ignored 11/24 PLS-00302: component 'V1' must be declared SQL> SQL> SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 for i in (select empno , ename , job from emp) loop 8 dbms_output.put_line(i.v1 || ' ' || i.v2 || ' ' || i.v3); 9 end loop; 10 end 11* ; SQL> / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------8/1 PL/SQL: Statement ignored 8/24 PLS-00302: component 'V1' must be declared SQL> SQL> ed; Wrote file afiedt.buf Oracle Complete PLSQL Reference

208

1 create or replace procedure rep1 2 is 3 begin 4 for i in (select empno , ename , job from emp) loop 5 dbms_output.put_line(i.empno || ' ' || i.ename || ' ' || i.job); 6 end loop; 7 end 8* ; SQL> / Procedure created. SQL> exec rep1; 7369 SMITH CLERK 7499 ALLEN SALESMAN 7521 WARD SALESMAN 7566 JONES MANAGER 7654 MARTIN SALESMAN 7698 BLAKE MANAGER 7782 CLARK MANAGER 7788 SCOTT ANALYST 7839 KING PRESIDENT 7844 TURNER SALESMAN 7876 ADAMS CLERK 7900 JAMES CLERK 7902 FORD ANALYST 7934 MILLER CLERK PL/SQL procedure successfully completed. SQL> SQL> SQL> create or replace procedure rep1 2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 for i in (select empno , ename , job from emp) loop 8 dbms_output.put_line(i.v1 || ' ' || i.v2 || ' ' || i.v3) 9 end loop; 10 end 11 ; 12 / Warning: Procedure created with compilation errors. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 Oracle Complete PLSQL Reference

209

2 is 3 v1 number(5); 4 v2 varchar2(20); 5 v3 varchar2(20); 6 begin 7 for i in (select empno , ename , job from emp) loop 8 v1 := i.empno; 9 v2 := i.ename; 10 v3 := i.job; 11 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3); 12 end loop; 13 end 14* ; SQL> / Procedure created. SQL> exec rep1; 7369 SMITH CLERK 7499 ALLEN SALESMAN 7521 WARD SALESMAN 7566 JONES MANAGER 7654 MARTIN SALESMAN 7698 BLAKE MANAGER 7782 CLARK MANAGER 7788 SCOTT ANALYST 7839 KING PRESIDENT 7844 TURNER SALESMAN 7876 ADAMS CLERK 7900 JAMES CLERK 7902 FORD ANALYST 7934 MILLER CLERK PL/SQL procedure successfully completed. SQL> SQL> SQL> spool off;

Oracle Complete PLSQL Reference

210

Cursor Example – Mohamed gamal course ============ SQL> SQL> SQL> SQL> select * FROM DEPT; DEPTNO DNAME LOC ---------- -------------- ------------10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a 60 b b 6 rows selected. SQL> SQL> SQL> create or replace procedure rep1 2 is 3 4 cursor zozo is select deptno , dname , loc from dept; 5 6 v1 number(5); 7 v2 varchar2(20); 8 v3 varchar2(20); 9 10 11 begin 12 open zozo; 13 14 fetch zozo into v1,v2,v3; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ); 16 17 close zozo; 18 19 end ; 20 / Procedure created. SQL> exec rep1; 10 ACCOUNTING NEW YORK PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf Oracle Complete PLSQL Reference

211

1 create or replace procedure rep1 2 is 3 cursor zozo is select deptno , dname , loc from dept; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 begin 8 open zozo; 9 for i in 1..6 loop 10 fetch zozo into v1,v2,v3; 11 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ); 12 end loop; 13 close zozo; 14* end ; 15 / Procedure created. SQL> exe crep1; SP2-0042: unknown command "exe crep1" - rest of line ignored. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a 60 b b PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor zozo is select deptno , dname , loc from dept; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 x number(5); 8 begin 9 select count(*) into x from dept; 10 open zozo; 11 for i in 1..x loop 12 fetch zozo into v1,v2,v3; 13 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ); 14 end loop; 15 close zozo; 16* end ; 17 / Procedure created. Oracle Complete PLSQL Reference

212

SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON 50 a 60 b b PL/SQL procedure successfully completed. SQL> delete from dept where deptno >=50; 2 rows deleted. SQL> commit; Commit complete. SQL> exec rep1; 10 ACCOUNTING NEW YORK 20 RESEARCH DALLAS 30 SALES CHICAGO 40 OPERATIONS BOSTON PL/SQL procedure successfully completed. SQL> select * from emp; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------- ---------- ---------- ---------7369 SMITH CLERK 7902 17/12/80 800 20 7499 ALLEN SALESMAN 7698 20/02/81 1600 300 30 7521 WARD SALESMAN 7698 22/02/81 1250 500 30 7566 JONES MANAGER 7839 02/04/81 2975 20 7654 MARTIN SALESMAN 7698 28/09/81 1250 1400 30 7698 BLAKE MANAGER 7839 01/05/81 2850 30 7782 CLARK MANAGER 7839 09/06/81 2450 10 7788 SCOTT ANALYST 7566 19/04/87 3000 20 7839 KING PRESIDENT 17/11/81 5000 10 7844 TURNER SALESMAN 7698 08/09/81 1500 0 30 7876 ADAMS CLERK 7788 23/05/87 1100 20 7900 JAMES CLERK 7698 03/12/81 950 30 7902 FORD ANALYST 7566 03/12/81 3000 20 7934 MILLER CLERK 7782 23/01/82 1300 10 14 rows selected. SQL> create or replace procedure rep1 2 is 3 4 cursor omar is select empno , ename , job from dept; Oracle Complete PLSQL Reference

213

5 6 v1 number(5); 7 v2 varchar2(20); 8 v3 varchar2(20); 9 10 11 begin 12 open omar; 13 14 fetch omar into v1,v2,v3; 15 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ); 16 17 close omar; 18 19 end ; 20 / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------4/16 PL/SQL: SQL Statement ignored 4/39 PL/SQL: ORA-00904: "JOB": invalid identifier SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job from emp; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 begin 8 open omar; 9 fetch omar into v1,v2,v3; 10 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ); 11 close omar; 12* end ; 13 / Procedure created. SQL> exec rep1; 7369 SMITH CLERK PL/SQL procedure successfully completed.

Oracle Complete PLSQL Reference

214

SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job from emp; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 begin 8 open omar; 9 for i in 1..14 loop 10 fetch omar into v1,v2,v3; 11 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ); 12 end loop; 13 close omar; 14* end ; 15 / Procedure created. SQL> exec rep1; 7369 SMITH CLERK 7499 ALLEN SALESMAN 7521 WARD SALESMAN 7566 JONES MANAGER 7654 MARTIN SALESMAN 7698 BLAKE MANAGER 7782 CLARK MANAGER 7788 SCOTT ANALYST 7839 KING PRESIDENT 7844 TURNER SALESMAN 7876 ADAMS CLERK 7900 JAMES CLERK 7902 FORD ANALYST 7934 MILLER CLERK PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job, sal from emp; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 begin 9 open omar; 10 for i in 1..14 loop Oracle Complete PLSQL Reference

215

11 fetch omar into v1,v2,v3, v4; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 '' || v4 ); 13 end loop; 14 close omar; 15* end ; SQL> / Warning: Procedure created with compilation errors. SQL> show err; Errors for PROCEDURE REP1: LINE/COL ERROR -------- ----------------------------------------------------------------12/52 PLS-00103: Encountered the symbol "" when expecting one of the following: . ( ) , * @ % & | = - + < / > at in is mod remainder not rem => .. or != or ~= >= at in is mod remainder not rem => .. or != or ~= >= ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 begin 9 open omar; 10 for i in 1..14 loop 11 fetch omar into v1,v2,v3,v4; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 13 end loop; 14 close omar; 15* end ; SQL> / Procedure created. Oracle Complete PLSQL Reference

216

SQL> exec rep1; 7369 SMITH CLERK 800 7499 ALLEN SALESMAN 1600 7521 WARD SALESMAN 1250 7566 JONES MANAGER 2975 7654 MARTIN SALESMAN 1250 7698 BLAKE MANAGER 2850 7782 CLARK MANAGER 2450 7788 SCOTT ANALYST 3000 7839 KING PRESIDENT 5000 7844 TURNER SALESMAN 1500 7876 ADAMS CLERK 1100 7900 JAMES CLERK 950 7902 FORD ANALYST 3000 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp order by sal desc; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 begin 9 open omar; 10 for i in 1..14 loop 11 fetch omar into v1,v2,v3,v4; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 13 end loop; 14 close omar; 15* end ; SQL> / Procedure created. SQL> exec rep1; 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7788 SCOTT ANALYST 3000 7566 JONES MANAGER 2975 7698 BLAKE MANAGER 2850 7782 CLARK MANAGER 2450 7499 ALLEN SALESMAN 1600 7844 TURNER SALESMAN 1500 7934 MILLER CLERK 1300 7521 WARD SALESMAN 1250 7654 MARTIN SALESMAN 1250 Oracle Complete PLSQL Reference

217

7876 ADAMS CLERK 1100 7900 JAMES CLERK 950 7369 SMITH CLERK 800 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp order by sal desc; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 begin 9 open omar; 10 for i in 1..5 loop 11 fetch omar into v1,v2,v3,v4; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 13 end loop; 14 close omar; 15* end ; SQL> / Procedure created. SQL> exec rep1; 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7788 SCOTT ANALYST 3000 7566 JONES MANAGER 2975 7698 BLAKE MANAGER 2850 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp order by sal asc; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 begin 9 open omar; 10 for i in 1..5 loop 11 fetch omar into v1,v2,v3,v4; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); Oracle Complete PLSQL Reference

218

13 end loop; 14 close omar; 15* end ; SQL> / Procedure created. SQL> exec rep1; 7369 SMITH CLERK 800 7900 JAMES CLERK 950 7876 ADAMS CLERK 1100 7521 WARD SALESMAN 1250 7654 MARTIN SALESMAN 1250 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = 10; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 begin 9 open omar; 10 for i in 1..14 loop 11 fetch omar into v1,v2,v3,v4; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 13 end loop; 14 close omar; 15* end ; SQL> / Procedure created. SQL> exec rep1; 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 7934 MILLER CLERK 1300 Oracle Complete PLSQL Reference

219

7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> select * from emp where deptno = 10; EMPNO ENAME JOB MGR HIREDATE SAL COMM ---------- ---------- --------- ---------- -------- ---------- ---------- ---------7782 CLARK MANAGER 7839 09/06/81 2450 10 7839 KING PRESIDENT 17/11/81 5000 10 7934 MILLER CLERK 7782 23/01/82 1300 10 SQL> ed; Wrote file afiedt.buf 1* select * from emp where deptno = 10 SQL> SQL> SQL> create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = 10; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 begin 9 open omar; 10 for i in 1..14 loop 11 fetch omar into v1,v2,v3,v4; 12 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 13 end loop; 14 close omar; 15 end ; 16 / Procedure created. SQL> ed; Wrote file afiedt.buf 1 2 3 4 5 6 7 8 9 10 11 12

create or replace procedure rep1 is cursor omar is select empno , ename , job , sal from emp where deptno = 10; v1 number(5); v2 varchar2(20); v3 varchar2(20); v4 number(5); begin open omar; for i in 1..3 loop fetch omar into v1,v2,v3,v4; dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 );

Oracle Complete PLSQL Reference

220

DEPTNO

13 end loop; 14 close omar; 15* end ; SQL> / Procedure created. SQL> exec rep1; 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = 10; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = 10; 11 open omar; 12 for i in 1..x loop 13 fetch omar into v1,v2,v3,v4; 14 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 15 end loop; 16 close omar; 17* end ; SQL> / Procedure created. SQL> exec rep1; 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> update emp set deptno = 10 where ename = 'FORD'; 1 row updated. SQL> commit; Commit complete. Oracle Complete PLSQL Reference

221

SQL> exec rep1; 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1* commit SQL> / Commit complete. SQL> create or replace procedure rep1 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = 10; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = 10; 11 open omar; 12 for i in 1..x loop 13 fetch omar into v1,v2,v3,v4; 14 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 15 end loop; 16 close omar; 17 end ; 18 / Procedure created. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 open omar; Oracle Complete PLSQL Reference

222

12 for i in 1..x loop 13 fetch omar into v1,v2,v3,v4; 14 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 15 end loop; 16 close omar; 17* end ; SQL> / Procedure created. SQL> exec rep1(10); 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> exec rep1(20); 7369 SMITH CLERK 800 7566 JONES MANAGER 2975 7788 SCOTT ANALYST 3000 7876 ADAMS CLERK 1100 PL/SQL procedure successfully completed. SQL> exec rep1(30); 7499 ALLEN SALESMAN 1600 7521 WARD SALESMAN 1250 7654 MARTIN SALESMAN 1250 7698 BLAKE MANAGER 2850 7844 TURNER SALESMAN 1500 7900 JAMES CLERK 950 PL/SQL procedure successfully completed. SQL> SQL> SQL> SQL> SQL> SQL> --%ISOPEN SQL> SQL> --%FOUND SQL> SQL> --%NOT FOUND SQL> SQL> --%rowcount SQL> SQL> SQL> SQL> ed; Oracle Complete PLSQL Reference

223

Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 if NOT omar%isopen then 12 dbms_output.put_line('Cursor Omar is not opened yet . please wait '); 13 end if; 14 open omar; 15 if omar%isopen then 16 dbms_output.put_line('Cursor Omar is opened successfully .please wait to fetch '); 17 end if; 18 for i in 1..x loop 19 fetch omar into v1,v2,v3,v4; 20 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 21 end loop; 22 close omar; 23* end ; 24 / Procedure created. SQL> exec rep1(10); Cursor Omar is not opened yet . please wait Cursor Omar is opened successfully .please wait to fetch 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; Oracle Complete PLSQL Reference

224

11 if NOT omar%isopen then 12 dbms_output.put_line('Cursor Omar is not opened yet . please wait '); 13 end if; 14 open omar; 15 if omar%isopen then 16 dbms_output.put_line('Cursor Omar is opened successfully .please wait to fetch '); 17 end if; 18 for i in 1..x loop 19 fetch omar into v1,v2,v3,v4; 20 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 21 end loop; 22 close omar; 23 dbms_output.put_line('Cursor Omar is closed . bye bye '); 24* end ; 25 / Procedure created. SQL> exec rep1(20); Cursor Omar is not opened yet . please wait Cursor Omar is opened successfully .please wait to fetch 7369 SMITH CLERK 800 7566 JONES MANAGER 2975 7788 SCOTT ANALYST 3000 7876 ADAMS CLERK 1100 Cursor Omar is closed . bye bye PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 open omar; 12 for i in 1..x loop 13 fetch omar into v1,v2,v3,v4; 14 if omar%found then 15 dbms_output.put_line('fe bayanat estana 7ageb7alak'); 16 end if; 17 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 18 end loop; 19 close omar; 20* end ; Oracle Complete PLSQL Reference

225

21 / Procedure created. SQL> exec rep1(10); fe bayanat estana 7ageb7alak 7782 CLARK MANAGER 2450 fe bayanat estana 7ageb7alak 7839 KING PRESIDENT 5000 fe bayanat estana 7ageb7alak 7902 FORD ANALYST 3000 fe bayanat estana 7ageb7alak 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 open omar; 12 for i in 1..x loop 13 fetch omar into v1,v2,v3,v4; 14 if omar%NOTfound then 15 dbms_output.put_line('mafesh bayanat mesh 7ageb7alak'); 16 end if; 17 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 18 end loop; 19 close omar; 20* end ; SQL> / Procedure created. SQL> exec rep1(70); PL/SQL procedure successfully completed. SQL> exec rep1(40); PL/SQL procedure successfully completed. SQL> ed; Oracle Complete PLSQL Reference

226

Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 open omar; 12 for i in 1..x+1 loop 13 fetch omar into v1,v2,v3,v4; 14 if omar%NOTfound then 15 dbms_output.put_line('mafesh bayanat mesh 7ageb7alak'); 16 end if; 17 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 18 end loop; 19 close omar; 20* end ; SQL> / Procedure created. SQL> exec rep1(10); 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7934 MILLER CLERK 1300 mafesh bayanat mesh 7ageb7alak 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> select * from emp order by deptno ; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO ---------- ---------- --------- ---------- -------- ---------- ---------- ---------7782 CLARK MANAGER 7839 09/06/81 2450 10 7902 FORD ANALYST 7566 03/12/81 3000 10 7839 KING PRESIDENT 17/11/81 5000 10 7934 MILLER CLERK 7782 23/01/82 1300 10 7369 SMITH CLERK 7902 17/12/80 800 20 7788 SCOTT ANALYST 7566 19/04/87 3000 20 7566 JONES MANAGER 7839 02/04/81 2975 20 7876 ADAMS CLERK 7788 23/05/87 1100 20 7499 ALLEN SALESMAN 7698 20/02/81 1600 300 30 7521 WARD SALESMAN 7698 22/02/81 1250 500 30 7844 TURNER SALESMAN 7698 08/09/81 1500 0 30 7698 BLAKE MANAGER 7839 01/05/81 2850 30 Oracle Complete PLSQL Reference

227

7654 MARTIN SALESMAN 7698 28/09/81 1250 7900 JAMES CLERK 7698 03/12/81 950

1400 30

30

14 rows selected. SQL> create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 open omar; 12 for i in 1..x+1 loop 13 fetch omar into v1,v2,v3,v4; 14 if omar%NOTfound then 15 dbms_output.put_line('mafesh bayanat mesh 7ageb7alak'); 16 end if; 17 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 18 end loop; 19 close omar; 20 end ; 21 / Procedure created. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 open omar; 12 for i in 1..x+5 loop 13 fetch omar into v1,v2,v3,v4; 14 if omar%NOTfound then 15 dbms_output.put_line('mafesh bayanat mesh 7ageb7alak'); 16 end if; 17 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 18 end loop; 19 close omar; 20* end ; Oracle Complete PLSQL Reference

228

SQL> / Procedure created. SQL> exec rep1(10); 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7934 MILLER CLERK 1300 mafesh bayanat mesh 7ageb7alak 7934 MILLER CLERK 1300 mafesh bayanat mesh 7ageb7alak 7934 MILLER CLERK 1300 mafesh bayanat mesh 7ageb7alak 7934 MILLER CLERK 1300 mafesh bayanat mesh 7ageb7alak 7934 MILLER CLERK 1300 mafesh bayanat mesh 7ageb7alak 7934 MILLER CLERK 1300 PL/SQL procedure successfully completed. SQL> ed; Wrote file afiedt.buf 1 create or replace procedure rep1(m number) 2 is 3 cursor omar is select empno , ename , job , sal from emp where deptno = m; 4 v1 number(5); 5 v2 varchar2(20); 6 v3 varchar2(20); 7 v4 number(5); 8 x number(5); 9 begin 10 select count(*) into x from emp where deptno = m; 11 open omar; 12 for i in 1..x loop 13 fetch omar into v1,v2,v3,v4; 14 dbms_output.put_line(v1 || ' ' || v2 || ' ' || v3 ||' ' || v4 ); 15 end loop; 16 dbms_output.put_line(omar%rowcount || '' || 'records'); 17 close omar; 18* end ; SQL> / Procedure created.

Oracle Complete PLSQL Reference

229

SQL> exec rep1(10); 7782 CLARK MANAGER 2450 7839 KING PRESIDENT 5000 7902 FORD ANALYST 3000 7934 MILLER CLERK 1300 4records PL/SQL procedure successfully completed.

SQL> exec rep1(20); 7369 SMITH CLERK 800 7566 JONES MANAGER 2975 7788 SCOTT ANALYST 3000 7876 ADAMS CLERK 1100 4records PL/SQL procedure successfully completed. SQL> exec rep1(30); 7499 ALLEN SALESMAN 1600 7521 WARD SALESMAN 1250 7654 MARTIN SALESMAN 1250 7698 BLAKE MANAGER 2850 7844 TURNER SALESMAN 1500 7900 JAMES CLERK 950 6records PL/SQL procedure successfully completed. SQL> spool off;

Oracle Complete PLSQL Reference

230

Oracle Complete PLSQL Reference

231

View more...

Comments

Copyright ©2017 KUPDF Inc.
SUPPORT KUPDF