Beruflich Dokumente
Kultur Dokumente
Email Id : trainings@cheyat.com
Contact IND : +91-91009
91009-98433/34(WAPP)
USA : +1(224) 676-9882
676
www.cheyat.com
COURSE CONTENT
Introduction to PL/SQL
PL/SQL Identifiers
Write Executable Statements
Interaction with the Oracle Server
Control Structures
Write Executable Statements
Composite Data Types
Explicit Cursors
Exception Handling
Stored Procedures and Functions
Create Stored Procedures
Create Stored Functions
Create Packages
Implement Oracle-Supplied
Supplied Packages in Application Development
Dynamic SQL
Design Considerations for PL/SQL Code
Describe Triggers
Create Compound, DDL, and Event Database Triggers
WHAT IS PL/SQL
Benefits of PL/SQL
– It is portable.
– You can declare identifiers
. – You can program with procedural language control structures.
– It can handle errors.
PL/SQL Block Structure
• DECLARE (optional)
– Variables, cursors, user-defined
defined exceptions
• BEGIN (mandatory)
– SQL statements – PL/SQL statements
• EXCEPTION (optional)
– Actions to perform when errors occur
• END; (mandatory)
IDENTIFIERS
• PL/SQL variables:
– Scalar
– Composite
– Reference
– Large object (LOB)
• Non-PL/SQL
PL/SQL variables: Bind variables
Handling Variables in PL/SQL
Variables are:
• Update Triggers:
BEFORE UPDATE Trigger
• Delete Triggers:
BEFORE DELETE Trigger
• Drop Triggers:
Drop a Trigger
• Disable/Enable Triggers:
Disable a Trigger
Enable a Trigger
Implicit Cursors
• These are created by default when DML statements like, INSERT, UPDATE, and DELETE
statements are executed.
• The set of rows returned by query is called active set.
• Oracle provides few attributes called as implicit cursor attributes to check the status of DML
operations. The are as follows
1) %FOUND
2) %NOTFOUND
3) %ROWCOUNT
4) %ISOPEN. 61
FOR E.G.
DECLARE
• n number(5);
• BEGIN
• UPDATE emp SET salary = salary + 1000;
• IF SQL%NOTFOUND THEN
• dbms_output.put_line('No sal are updated');
• ELSIF SQL%FOUND THEN
• n := SQL%ROWCOUNT;
• dbms_output.put_line('Sal for ' ||n || 'employees are
updated');
• END IF;
• END;
•/
EXPLANATION
• Open cursor_name
• For e.g.
• Open c_name
• Where c_name is the name of cursor.
• Open statement retrieves the records from db and places in the cursor(private
sql area).
Fetching data from cursor
• The fetch statement retrieves the rows from the active set one row at a time. The fetch statement is used usually
used in conjunction with iterative process (looping statements
statements)
• Syntax: FETCH cursor-name INTO record-list
• Ex: LOOP
• -----------
• ------------
• FETCH c_name INTO name;
• -----------
• END LOOP;
Closing cursor
Closing a cursor:
• Closing statement closes/deactivates/disables the previously opened cursor
and makes the active set undefined.
• Syntax : CLOSE cursor_name 69
• 70. Cursor can store multiple rows at a time but without loop cursor cannot
fetch multiple rows but only print very first row from your result e.g. on next
slide
PACKAGES
• A Package is a container that may have many functions and procedures within
it.
• A PACKAGE is a group of programmatic constructs combined.
• A package is a schema object that groups logically related PL/SQL types,
items, and subprograms
Contact IND : +91-91009-98433/34
98433/34 (WAPP)
USA : +1(224) 676676-9882
Email ID : trainings@cheyat.com
Website : http://cheyat.com
://cheyat.com/
Skype ID: cheyatTraining