SlideShare uma empresa Scribd logo
1 de 48
Baixar para ler offline
PL/SQL TUTORIAL
Doan Quang MinhApril
10, 2012 CTI Cosatech VN
About this slide
This Oracle PL/SQL tutorial guides you the
basics of programming in PL/SQL with appropriate
examples. You can use this tutorial as your
reference while programming with PL/SQL.
You should have basic knowledge about SQL
and database management before reading this.
2
Agenda
I. Introduction (5 minutes)
II. Basic syntax (15 minutes)
III. Advanced syntax (30 minutes)
IV. Conclusion (2 minutes)
V. Reference (2 minutes)
VI. Keywords (3 minutes)
VII. Q&A
3
I. Introduction
1. Introduction to PL/SQL
 What is PL/SQL?
 The PL/SQL Engine
2. Advantages of PL/SQL
 Block Structures
 Procedural Language Capability
 Better Performance
 Error Handling
4
1. Introduction to PL/SQL
What is PL/SQL?
 Procedural Language extension of SQL.
 PL/SQL is a combination of SQL along with the
procedural features of programming languages. It
was developed by Oracle Corporation in the early
90’s to enhance the capabilities of SQL.
5
I. Introduction
1. Introduction to PL/SQL(cont)
The PL/SQL Engine
 Oracle uses a PL/SQL engine to processes the
PL/SQL statements.
 A PL/SQL code can be stored in the client system
(client-side) or in the database (server-side).
6
I. Introduction
2. Advantages of PL/SQL
 Block Structures: PL SQL consists of blocks of
code, which can be nested within each other. Each
block forms a unit of a task or a logical module.
PL/SQL Blocks can be stored in the database and
reused.
 Procedural Language Capability: PL SQL consists
of procedural language constructs such as
conditional statements (if else statements) and
loops like (FOR loops).
7
I. Introduction
2. Advantages of PL/SQL(cont)
 Better Performance: PL SQL engine processes
multiple SQL statements simultaneously as a single
block, thereby reducing network traffic.
 Error Handling: PL/SQL handles errors or
exceptions effectively during the execution of a
PL/SQL program. Once an exception is
caught, specific actions can be taken depending
upon the type of the exception or it can be displayed
to the user with a message.
8
I. Introduction
II. Basic syntax
1. Block Structures
2. Operators
3. Comments
4. Delimiters
5. Variables
6. Constants
7. Records
8. Conditional Statements
9. Iterative Statements
9
1. Block Structures
 Basic block
[DECLARE]
Variable declaration
BEGIN
Program Execution
[EXCEPTION]
Exception handling
END;
10
II. Basic syntax
 Example
SET SERVEROUTPUT ON SIZE 1000000
BEGIN
dbms_output.put_line('Hello PL/SQL');
END;
2. Operators
 Comparison operators
NOT IS NULL LIKE BETWEEN IN AND OR
+ - * / @ ; = <> != || <= >=
 Assignment operator
:= (You can assign values to a variable, literal value, or function call
but NOT a table column)
11
II. Basic syntax
3. Comments
 Comment
-- comment
/* comment */
 Example
DECLARE
/* Multi-line comments are not required to actually use
multiple lines. */
BEGIN
-- This is a single line comment
NULL;
END;
12
II. Basic syntax
4. Delimiters
 Delimiter
Item separator .
Character string delimiter '
Quoted String delimiter "
Bind variable indicator :
Attribute indicator %
Statement terminator ;
 Example
job_record.jobname := 'Test Job';
v_empno emp.empno%TYPE := &empno;
13
II. Basic syntax
5. Variables
 Variable
variable_name datatype [NOT NULL := value ];
 Example
DECLARE
v_first_name VARCHAR2(20);
v_employee_id NUMBER NOT NULL;
v_last_name EMPLOYEES.LAST_NAME%TYPE;
v_employee EMPLOYEES%ROWTYPE;
v_hire_date DATE;
BEGIN
NULL;
END;
14
II. Basic syntax
6. Constants
 Constant
constant_name CONSTANT datatype := VALUE;
 Example
DECLARE
c_boss CONSTANT VARCHAR2(4) := ‘BOSS’;
BEGIN
NULL;
END;
15
II. Basic syntax
7. Records
 Record
TYPE record_type_name IS RECORD(
first_col_name column_datatype,
second_col_name column_datatype, ...);
record_name record_type_name;
 Example
DECLARE
TYPE employee IS RECORD(
v_employee_id NUMBER NOT NULL
,v_first_name VARCHAR2(20));
v_employee employee;
BEGIN
NULL;
END;
16
II. Basic syntax
8. Conditional Statements
 If statement
IF condition THEN
statement 1;
ELSE
statement 2;
END IF;
17
II. Basic syntax
 Example
IF v_employee.sal > 0 THEN
v_employee.sal := 1;
ELSE
v_employee.sal := 0;
END IF;
9. Iterative Statements
 Iterative statement
LOOP
statements;
EXIT WHEN condition; (EXIT;)
END LOOP;
WHILE <condition>
LOOP statements;
END LOOP;
FOR counter IN val1..val2
LOOP statements;
END LOOP;
18
II. Basic syntax
 Example
LOOP
monthly_val := daily_val * 31;
EXIT WHEN monthly_value > 4000;
END LOOP;
WHILE monthly_val <= 4000
LOOP monthly_val := daily_val * 31;
END LOOP;
FOR counter IN 1..9
LOOP monthly_val := daily_val * 31;
END LOOP;
III. Advanced syntax
1. Cursors
2. Explicit Cursors
3. Procedures
4. Functions
5. Parameters-Procedure, Function
6. Exception Handling
7. Triggers
19
1. Cursors
 What is cursor ?
 In memory work area
 Store rows selected from DB
 Process one row per time only
 Active set is the set of rows the cursor hold.
 Supported attributes
 %FOUND
 %NOTFOUND
 %ROWCOUNT
 %ISOPEN
20
III. Advanced
1. Cursors(cont)
 Two types of cursors in PL/SQL
 Implicit cursors
 Explicit cursors
 Implicit cursors
These are created by default when DML statements
like, INSERT, UPDATE, and DELETE statements are
executed. They are also created when a SELECT statement
that returns just one row is executed.
21
III. Advanced
1. Cursors(cont)
 Example
DECLARE
v_rows number(5);
BEGIN
UPDATE employee
SET salary = salary + 1000;
IF SQL%NOTFOUND THEN
dbms_output.put_line('None of the salaries where updated');
ELSIF SQL%FOUND THEN
v_rows := SQL%ROWCOUNT;
dbms_output.put_line('Salaries for ' || v_rows || 'employees are
updated');
END IF;
END;
22
III. Advanced
2. Explicit Cursors
 What is explicit cursor ?
An explicit cursor is defined in the declaration section of the PL/SQL
Block. It is created on a SELECT Statement which returns more than one row.
We can provide a suitable name for the cursor.
 How to use explicit cursors ?
 DECLARE the cursor in the declaration section.
 OPEN the cursor in the Execution Section.
 FETCH the data from cursor into PL/SQL variables or records in the
Execution Section.
 CLOSE the cursor in the Execution Section before you end the PL/SQL
Block.
23
III. Advanced
2. Explicit Cursors
 Example
 Declaring a cursor
DECLARE
CURSOR emp_cur IS
SELECT *
FROM emp_tbl
WHERE salary > 5000;
24
III. Advanced
 Accessing the cursor
BEGIN
OPEN emp_cur;
FETCH emp_cur INTO v_record;
process_one_record(v_record);
CLOSE emp_cur;
END;
3. Procedures
 What is procedures ?
 A named PL/SQL block
 A procedure has a header and a body
 May or may not return values
 If stored on DBMS, we call it stored procedures
25
III. Advanced
3. Procedures(cont)
 Declaration
CREATE [OR REPLACE] PROCEDURE proc_name [list of parameters]
IS
Declaration section
BEGIN
Execution section
EXCEPTION
Exception section
END;
 Execution
 From the SQL prompt : EXECUTE [or EXEC]
procedure_name;
 Within another procedure: procedure_name;
26
III. Advanced
3. Procedures(cont)
 Example
CREATE OR REPLACE PROCEDURE employer_details IS
CURSOR emp_cur IS
SELECT first_name, last_name, salary
FROM emp_tbl;
emp_rec emp_cur%ROWTYPE;
BEGIN
FOR emp_rec IN sales_cur
LOOP
dbms_output.put_line(emp_cur.first_name);
END LOOP;
END;
EXECUTE employer_details;
27
III. Advanced
4. Functions
 What is functions?
 A named PL/SQL block
 A function has a header and a body
 Must always return a value (different to a procedure)
 If stored on DBMS, we call it stored functions
28
III. Advanced
4. Functions(cont)
 Declaration
CREATE [OR REPLACE] FUNCTION function_name [parameters]
RETURN return_datatype;
IS Declaration_section
BEGIN
Execution_section
Return return_variable;
EXCEPTION
exception section
Return return_variable;
END;
29
III. Advanced
4. Functions(cont)
 Execution
 Since a function returns a value we can assign it to a variable
variable_name := function_name;
 As a part of a SELECT statement
SELECT function_name FROM table;
 In a PL/SQL Statements like,
dbms_output.put_line(function_name);
30
III. Advanced
4. Functions(cont)
 Example
CREATE OR REPLACE FUNCTION employer_details_func
RETURN VARCHAR(20);
IS
emp_name VARCHAR(20);
BEGIN
SELECT first_name INTO emp_name
FROM emp_tbl
WHERE empID = '100';
RETURN emp_name;
END;
SELECT employer_details_func FROM dual;
31
III. Advanced
5. Parameters in Procedure,
Functions
 3 ways to pass parameters
 IN-parameters
 OUT-parameters
 IN OUT-parameters
NOTE: If a parameter is not explicitly defined a parameter type, then
by default it is an IN type parameter.
32
III. Advanced
5. Parameters in
Procedure, Functions
 Example
CREATE OR REPLACE PROCEDURE emp_name (
p_id IN NUMBER
, p_emp_name OUT VARCHAR2(20))
IS
BEGIN
SELECT first_name INTO p_emp_name
FROM emp_tbl WHERE empID = p_id;
END;
33
III. Advanced
6. Exception Handling
34
III. Advanced
 What is a exception handling?
 A feature to handle the Exceptions which occur in a PL/SQL
Block
 Avoid the source code from exiting abruptly
 When an exception occurs a messages which explains its
cause is received
 3 parts of an PL/SQL exception?
• Type of Exception
• An Error Code
• A message
6. Exception Handling
35
III. Advanced
 Structure of Exception Handling
EXCEPTION
WHEN ex_name1 THEN
-- Error handling statements
WHEN ex_name2 THEN
-- Error handling statements
WHEN Others THEN
-- Error handling statements
6. Exception Handling
36
III. Advanced
 3 types of exception
 Named System Exceptions
 Unnamed System Exceptions
 User-defined Exceptions
6. Exception Handling
37
III. Advanced
 Example
BEGIN
-- Execution section
EXCEPTION
WHEN NO_DATA_FOUND THEN
dbms_output.put_line ('A SELECT...INTO did not return any
row.');
END;
7. Triggers
 What is a Trigger?
A trigger is a pl/sql block structure which is fired when a DML
statements like Insert, Delete, Update is executed on a database
table. A trigger is triggered automatically when an associated
DML statement is executed.
38
III. Advanced
7. Triggers(cont)
 How to create a trigger?
CREATE [OR REPLACE ] TRIGGER trigger_name
{BEFORE | AFTER | INSTEAD OF }
{INSERT [OR] | UPDATE [OR] | DELETE}
[OF col_name]
ON table_name
[REFERENCING OLD AS o NEW AS n]
[FOR EACH ROW]
WHEN (condition)
BEGIN
--- sql statements
END;
39
III. Advanced
7. Triggers(cont)
 Example
The price of a product changes constantly. It is important to
maintain the history of the prices of the products.
We can create a trigger to update the 'product_price_history' table
when the price of the product is updated in the 'product' table.
1. Create the 'product' table and 'product_price_history' table
40
III. Advanced
CREATE TABLE product_price_history
(product_id NUMBER(5)
,product_name VARCHAR2(32)
,supplier_name VARCHAR2(32)
,unit_price NUMBER(7,2) );
CREATE TABLE product
(product_id NUMBER(5)
,product_name VARCHAR2(32)
,supplier_name VARCHAR2(32)
,unit_price NUMBER(7,2) );
7. Triggers(cont)
 Example(cont)
2. Create the price_history_trigger and execute it.
41
III. Advanced
CREATE OR REPLACE TRIGGER price_history_trigger
BEFORE UPDATE OF unit_price
ON product
FOR EACH ROW
BEGIN
INSERT INTO product_price_history
VALUES
(:old.product_id,
:old.product_name,
:old.supplier_name,
:old.unit_price);
END;
7. Triggers(cont)
 Example(cont)
3. Lets update the price of a product.
-- Once executed, the trigger fires and updates the
-- product_price_history' table
UPDATE PRODUCT SET unit_price = 800 WHERE product_id = 100
4. If you ROLLBACK the transaction before committing to the database, the data
inserted to the table is also rolled back.
42
III. Advanced
7. Triggers(cont)
 Types of PL/SQL Triggers
 Row level trigger - An event is triggered for each row updated, inserted or
deleted
 Statement level trigger - An event is triggered for each SQL statement
executed
 PL/SQL Trigger Execution Hierarchy
 BEFORE statement trigger fires first
 Next BEFORE row level trigger fires, once for each row affected
 Then AFTER row level trigger fires once for each affected row. This events
will alternates between BEFORE and AFTER row level triggers
 Finally the AFTER statement level trigger fires
43
III. Advanced
7. Triggers(cont)
 How To know Information about Triggers.
 We can use the data dictionary view 'USER_TRIGGERS' to obtain
information about any trigger.
DESC USER_TRIGGERS;
 This view stores information about header and body of the trigger
SELECT * FROM user_triggers WHERE trigger_name =
'trigger_name';
 You can drop a trigger using the following command.
DROP TRIGGER trigger_name;
44
III. Advanced
IV. Conclusion
45
Now, I hope this slide gave you some ideas about working with PL/SQL.
Please let me know if there’s any mistake or issue in the tutorial. All
comments are welcome.
With our position in CTI Vietnam. This amount of knowledge would not be
enough for us. There’re many more topics we need to invest our time:
performance tuning, data mining, coding convention, best practices, …
So, let’s share our knowledge, TOGETHER.
V. Reference
46
1. PL/SQL Tutorial from plsql-tutorial.com
2. PL/SQL User's Guide and Reference, Release 2 (9.2), from
Oracle
3. Database Interaction with PL/SQL, Jagadish Chatarji (Dev
Shed)
4. PL/SQL Code Examples, ACS department, University of
Utah
5. Doing SQL from PL/SQL: Best and Worst Practices, Oracle
VI. Keywords
47
Below is some keywords not mentioned in this slide. If possible, you should
google them.
General: Embedded SQL, Native dynamic SQL, The DBMS_Sql API,
Name resolution, PL/SQL compiler, bounded and unbounded, oracle
hint, materialized view.
Cursors: sharable SQL structure, session cursor, ref cursor, cursor
variable, strong ref cursor, weak ref cursor, identified cursor, DBMS_Sql
numeric cursor.
Exception Handling: RAISE_APPLICATION_ERROR, PRAGMA,
EXCEPTION_INIT.
Triggers: CYCLIC CASCADING, ROLLBACK, INSTEAD OF,
REFERENCING OLD.
VII. Q&A
48
Questions, please
...

Mais conteúdo relacionado

Mais procurados (20)

Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
4. plsql
4. plsql4. plsql
4. plsql
 
Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01Oracle - Program with PL/SQL - Lession 01
Oracle - Program with PL/SQL - Lession 01
 
Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
Procedures and triggers in SQL
Procedures and triggers in SQLProcedures and triggers in SQL
Procedures and triggers in SQL
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
 
PL/SQL
PL/SQLPL/SQL
PL/SQL
 
Pl sql guide
Pl sql guidePl sql guide
Pl sql guide
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
03 Writing Control Structures, Writing with Compatible Data Types Using Expli...
 
10 Creating Triggers
10 Creating Triggers10 Creating Triggers
10 Creating Triggers
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
 
plsql les10
 plsql les10 plsql les10
plsql les10
 
Chapter8 pl sql
Chapter8 pl sqlChapter8 pl sql
Chapter8 pl sql
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptions
 
PLSQL Cursors
PLSQL CursorsPLSQL Cursors
PLSQL Cursors
 
Sql commands
Sql commandsSql commands
Sql commands
 

Destaque

Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideSrinimf-Slides
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorialbunny0143
 
INYECCION SQL(SEGURIDAD DE LA INFORMACION)
INYECCION SQL(SEGURIDAD DE LA INFORMACION)INYECCION SQL(SEGURIDAD DE LA INFORMACION)
INYECCION SQL(SEGURIDAD DE LA INFORMACION)toshko86
 
Ims11 ims13 application programming enhancements - IMS UG May 2014 Sydney & ...
Ims11  ims13 application programming enhancements - IMS UG May 2014 Sydney & ...Ims11  ims13 application programming enhancements - IMS UG May 2014 Sydney & ...
Ims11 ims13 application programming enhancements - IMS UG May 2014 Sydney & ...Robert Hain
 
Oracle Sql developer tutorial
Oracle Sql developer tutorialOracle Sql developer tutorial
Oracle Sql developer tutorialAsad Masood Qazi
 
Dotnet difference questions & answers Compiled-1
Dotnet difference questions & answers Compiled-1Dotnet difference questions & answers Compiled-1
Dotnet difference questions & answers Compiled-1Umar Ali
 
Plsql triggers
Plsql triggersPlsql triggers
Plsql triggersAz Za
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming TechniquesRaji Ghawi
 
Colorectal Cancer-A Rising Concern
Colorectal Cancer-A Rising ConcernColorectal Cancer-A Rising Concern
Colorectal Cancer-A Rising ConcernIsDocIn .
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJDharita Chokshi
 
Joins in databases
Joins in databases Joins in databases
Joins in databases CourseHunt
 

Destaque (20)

Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
 
Oracle: Cursors
Oracle: CursorsOracle: Cursors
Oracle: Cursors
 
Oracle PLSql 4
Oracle PLSql 4Oracle PLSql 4
Oracle PLSql 4
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
 
INYECCION SQL(SEGURIDAD DE LA INFORMACION)
INYECCION SQL(SEGURIDAD DE LA INFORMACION)INYECCION SQL(SEGURIDAD DE LA INFORMACION)
INYECCION SQL(SEGURIDAD DE LA INFORMACION)
 
Ims11 ims13 application programming enhancements - IMS UG May 2014 Sydney & ...
Ims11  ims13 application programming enhancements - IMS UG May 2014 Sydney & ...Ims11  ims13 application programming enhancements - IMS UG May 2014 Sydney & ...
Ims11 ims13 application programming enhancements - IMS UG May 2014 Sydney & ...
 
Oracle Sql developer tutorial
Oracle Sql developer tutorialOracle Sql developer tutorial
Oracle Sql developer tutorial
 
Dotnet difference questions & answers Compiled-1
Dotnet difference questions & answers Compiled-1Dotnet difference questions & answers Compiled-1
Dotnet difference questions & answers Compiled-1
 
Plsql triggers
Plsql triggersPlsql triggers
Plsql triggers
 
Database Programming Techniques
Database Programming TechniquesDatabase Programming Techniques
Database Programming Techniques
 
Colorectal Cancer-A Rising Concern
Colorectal Cancer-A Rising ConcernColorectal Cancer-A Rising Concern
Colorectal Cancer-A Rising Concern
 
Payilagam oracle sql & plsql training syllabus
Payilagam oracle sql & plsql training syllabusPayilagam oracle sql & plsql training syllabus
Payilagam oracle sql & plsql training syllabus
 
En ch23
En ch23En ch23
En ch23
 
Database lab manual
Database lab manualDatabase lab manual
Database lab manual
 
SQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJSQL, Embedded SQL, Dynamic SQL and SQLJ
SQL, Embedded SQL, Dynamic SQL and SQLJ
 
Eer case study
Eer case studyEer case study
Eer case study
 
Joins in databases
Joins in databases Joins in databases
Joins in databases
 
Adbms
AdbmsAdbms
Adbms
 
Chapter02
Chapter02Chapter02
Chapter02
 

Semelhante a PLSQL Tutorial (20)

Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
Unit 3(rdbms)
Unit 3(rdbms)Unit 3(rdbms)
Unit 3(rdbms)
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)DAC training-batch -2020(PLSQL)
DAC training-batch -2020(PLSQL)
 
Functions oracle (pl/sql)
Functions oracle (pl/sql)Functions oracle (pl/sql)
Functions oracle (pl/sql)
 
plsql.ppt
plsql.pptplsql.ppt
plsql.ppt
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
PLSQL.pptx
PLSQL.pptxPLSQL.pptx
PLSQL.pptx
 
Procedures andcursors
Procedures andcursorsProcedures andcursors
Procedures andcursors
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Stored procedure
Stored procedureStored procedure
Stored procedure
 
Oracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online TrainingOracle PL/SQL online training | PL/SQL online Training
Oracle PL/SQL online training | PL/SQL online Training
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Introduction to mysql part 3
Introduction to mysql part 3Introduction to mysql part 3
Introduction to mysql part 3
 
PL-SQL.pdf
PL-SQL.pdfPL-SQL.pdf
PL-SQL.pdf
 
Module04
Module04Module04
Module04
 
PLSQL (1).ppt
PLSQL (1).pptPLSQL (1).ppt
PLSQL (1).ppt
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Exceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant BhabadExceptions Triggers function in SQL by Vasant Bhabad
Exceptions Triggers function in SQL by Vasant Bhabad
 

Último

activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfJamie (Taka) Wang
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintMahmoud Rabie
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7DianaGray10
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarPrecisely
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXTarek Kalaji
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8DianaGray10
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Adtran
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfDianaGray10
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfinfogdgmi
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Websitedgelyza
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?IES VE
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Brian Pichman
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Commit University
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfAijun Zhang
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding TeamAdam Moalla
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesMd Hossain Ali
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostMatt Ray
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureEric D. Schabell
 

Último (20)

activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
activity_diagram_combine_v4_20190827.pdfactivity_diagram_combine_v4_20190827.pdf
 
Empowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership BlueprintEmpowering Africa's Next Generation: The AI Leadership Blueprint
Empowering Africa's Next Generation: The AI Leadership Blueprint
 
20150722 - AGV
20150722 - AGV20150722 - AGV
20150722 - AGV
 
UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7UiPath Studio Web workshop series - Day 7
UiPath Studio Web workshop series - Day 7
 
AI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity WebinarAI You Can Trust - Ensuring Success with Data Integrity Webinar
AI You Can Trust - Ensuring Success with Data Integrity Webinar
 
VoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBXVoIP Service and Marketing using Odoo and Asterisk PBX
VoIP Service and Marketing using Odoo and Asterisk PBX
 
UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8UiPath Studio Web workshop series - Day 8
UiPath Studio Web workshop series - Day 8
 
Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™Meet the new FSP 3000 M-Flex800™
Meet the new FSP 3000 M-Flex800™
 
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdfUiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
UiPath Solutions Management Preview - Northern CA Chapter - March 22.pdf
 
Videogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdfVideogame localization & technology_ how to enhance the power of translation.pdf
Videogame localization & technology_ how to enhance the power of translation.pdf
 
COMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a WebsiteCOMPUTER 10 Lesson 8 - Building a Website
COMPUTER 10 Lesson 8 - Building a Website
 
How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?How Accurate are Carbon Emissions Projections?
How Accurate are Carbon Emissions Projections?
 
Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )Building Your Own AI Instance (TBLC AI )
Building Your Own AI Instance (TBLC AI )
 
Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)Crea il tuo assistente AI con lo Stregatto (open source python framework)
Crea il tuo assistente AI con lo Stregatto (open source python framework)
 
Machine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdfMachine Learning Model Validation (Aijun Zhang 2024).pdf
Machine Learning Model Validation (Aijun Zhang 2024).pdf
 
9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team9 Steps For Building Winning Founding Team
9 Steps For Building Winning Founding Team
 
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just MinutesAI Fame Rush Review – Virtual Influencer Creation In Just Minutes
AI Fame Rush Review – Virtual Influencer Creation In Just Minutes
 
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCostKubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
KubeConEU24-Monitoring Kubernetes and Cloud Spend with OpenCost
 
20230104 - machine vision
20230104 - machine vision20230104 - machine vision
20230104 - machine vision
 
OpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability AdventureOpenShift Commons Paris - Choose Your Own Observability Adventure
OpenShift Commons Paris - Choose Your Own Observability Adventure
 

PLSQL Tutorial

  • 1. PL/SQL TUTORIAL Doan Quang MinhApril 10, 2012 CTI Cosatech VN
  • 2. About this slide This Oracle PL/SQL tutorial guides you the basics of programming in PL/SQL with appropriate examples. You can use this tutorial as your reference while programming with PL/SQL. You should have basic knowledge about SQL and database management before reading this. 2
  • 3. Agenda I. Introduction (5 minutes) II. Basic syntax (15 minutes) III. Advanced syntax (30 minutes) IV. Conclusion (2 minutes) V. Reference (2 minutes) VI. Keywords (3 minutes) VII. Q&A 3
  • 4. I. Introduction 1. Introduction to PL/SQL  What is PL/SQL?  The PL/SQL Engine 2. Advantages of PL/SQL  Block Structures  Procedural Language Capability  Better Performance  Error Handling 4
  • 5. 1. Introduction to PL/SQL What is PL/SQL?  Procedural Language extension of SQL.  PL/SQL is a combination of SQL along with the procedural features of programming languages. It was developed by Oracle Corporation in the early 90’s to enhance the capabilities of SQL. 5 I. Introduction
  • 6. 1. Introduction to PL/SQL(cont) The PL/SQL Engine  Oracle uses a PL/SQL engine to processes the PL/SQL statements.  A PL/SQL code can be stored in the client system (client-side) or in the database (server-side). 6 I. Introduction
  • 7. 2. Advantages of PL/SQL  Block Structures: PL SQL consists of blocks of code, which can be nested within each other. Each block forms a unit of a task or a logical module. PL/SQL Blocks can be stored in the database and reused.  Procedural Language Capability: PL SQL consists of procedural language constructs such as conditional statements (if else statements) and loops like (FOR loops). 7 I. Introduction
  • 8. 2. Advantages of PL/SQL(cont)  Better Performance: PL SQL engine processes multiple SQL statements simultaneously as a single block, thereby reducing network traffic.  Error Handling: PL/SQL handles errors or exceptions effectively during the execution of a PL/SQL program. Once an exception is caught, specific actions can be taken depending upon the type of the exception or it can be displayed to the user with a message. 8 I. Introduction
  • 9. II. Basic syntax 1. Block Structures 2. Operators 3. Comments 4. Delimiters 5. Variables 6. Constants 7. Records 8. Conditional Statements 9. Iterative Statements 9
  • 10. 1. Block Structures  Basic block [DECLARE] Variable declaration BEGIN Program Execution [EXCEPTION] Exception handling END; 10 II. Basic syntax  Example SET SERVEROUTPUT ON SIZE 1000000 BEGIN dbms_output.put_line('Hello PL/SQL'); END;
  • 11. 2. Operators  Comparison operators NOT IS NULL LIKE BETWEEN IN AND OR + - * / @ ; = <> != || <= >=  Assignment operator := (You can assign values to a variable, literal value, or function call but NOT a table column) 11 II. Basic syntax
  • 12. 3. Comments  Comment -- comment /* comment */  Example DECLARE /* Multi-line comments are not required to actually use multiple lines. */ BEGIN -- This is a single line comment NULL; END; 12 II. Basic syntax
  • 13. 4. Delimiters  Delimiter Item separator . Character string delimiter ' Quoted String delimiter " Bind variable indicator : Attribute indicator % Statement terminator ;  Example job_record.jobname := 'Test Job'; v_empno emp.empno%TYPE := &empno; 13 II. Basic syntax
  • 14. 5. Variables  Variable variable_name datatype [NOT NULL := value ];  Example DECLARE v_first_name VARCHAR2(20); v_employee_id NUMBER NOT NULL; v_last_name EMPLOYEES.LAST_NAME%TYPE; v_employee EMPLOYEES%ROWTYPE; v_hire_date DATE; BEGIN NULL; END; 14 II. Basic syntax
  • 15. 6. Constants  Constant constant_name CONSTANT datatype := VALUE;  Example DECLARE c_boss CONSTANT VARCHAR2(4) := ‘BOSS’; BEGIN NULL; END; 15 II. Basic syntax
  • 16. 7. Records  Record TYPE record_type_name IS RECORD( first_col_name column_datatype, second_col_name column_datatype, ...); record_name record_type_name;  Example DECLARE TYPE employee IS RECORD( v_employee_id NUMBER NOT NULL ,v_first_name VARCHAR2(20)); v_employee employee; BEGIN NULL; END; 16 II. Basic syntax
  • 17. 8. Conditional Statements  If statement IF condition THEN statement 1; ELSE statement 2; END IF; 17 II. Basic syntax  Example IF v_employee.sal > 0 THEN v_employee.sal := 1; ELSE v_employee.sal := 0; END IF;
  • 18. 9. Iterative Statements  Iterative statement LOOP statements; EXIT WHEN condition; (EXIT;) END LOOP; WHILE <condition> LOOP statements; END LOOP; FOR counter IN val1..val2 LOOP statements; END LOOP; 18 II. Basic syntax  Example LOOP monthly_val := daily_val * 31; EXIT WHEN monthly_value > 4000; END LOOP; WHILE monthly_val <= 4000 LOOP monthly_val := daily_val * 31; END LOOP; FOR counter IN 1..9 LOOP monthly_val := daily_val * 31; END LOOP;
  • 19. III. Advanced syntax 1. Cursors 2. Explicit Cursors 3. Procedures 4. Functions 5. Parameters-Procedure, Function 6. Exception Handling 7. Triggers 19
  • 20. 1. Cursors  What is cursor ?  In memory work area  Store rows selected from DB  Process one row per time only  Active set is the set of rows the cursor hold.  Supported attributes  %FOUND  %NOTFOUND  %ROWCOUNT  %ISOPEN 20 III. Advanced
  • 21. 1. Cursors(cont)  Two types of cursors in PL/SQL  Implicit cursors  Explicit cursors  Implicit cursors These are created by default when DML statements like, INSERT, UPDATE, and DELETE statements are executed. They are also created when a SELECT statement that returns just one row is executed. 21 III. Advanced
  • 22. 1. Cursors(cont)  Example DECLARE v_rows number(5); BEGIN UPDATE employee SET salary = salary + 1000; IF SQL%NOTFOUND THEN dbms_output.put_line('None of the salaries where updated'); ELSIF SQL%FOUND THEN v_rows := SQL%ROWCOUNT; dbms_output.put_line('Salaries for ' || v_rows || 'employees are updated'); END IF; END; 22 III. Advanced
  • 23. 2. Explicit Cursors  What is explicit cursor ? An explicit cursor is defined in the declaration section of the PL/SQL Block. It is created on a SELECT Statement which returns more than one row. We can provide a suitable name for the cursor.  How to use explicit cursors ?  DECLARE the cursor in the declaration section.  OPEN the cursor in the Execution Section.  FETCH the data from cursor into PL/SQL variables or records in the Execution Section.  CLOSE the cursor in the Execution Section before you end the PL/SQL Block. 23 III. Advanced
  • 24. 2. Explicit Cursors  Example  Declaring a cursor DECLARE CURSOR emp_cur IS SELECT * FROM emp_tbl WHERE salary > 5000; 24 III. Advanced  Accessing the cursor BEGIN OPEN emp_cur; FETCH emp_cur INTO v_record; process_one_record(v_record); CLOSE emp_cur; END;
  • 25. 3. Procedures  What is procedures ?  A named PL/SQL block  A procedure has a header and a body  May or may not return values  If stored on DBMS, we call it stored procedures 25 III. Advanced
  • 26. 3. Procedures(cont)  Declaration CREATE [OR REPLACE] PROCEDURE proc_name [list of parameters] IS Declaration section BEGIN Execution section EXCEPTION Exception section END;  Execution  From the SQL prompt : EXECUTE [or EXEC] procedure_name;  Within another procedure: procedure_name; 26 III. Advanced
  • 27. 3. Procedures(cont)  Example CREATE OR REPLACE PROCEDURE employer_details IS CURSOR emp_cur IS SELECT first_name, last_name, salary FROM emp_tbl; emp_rec emp_cur%ROWTYPE; BEGIN FOR emp_rec IN sales_cur LOOP dbms_output.put_line(emp_cur.first_name); END LOOP; END; EXECUTE employer_details; 27 III. Advanced
  • 28. 4. Functions  What is functions?  A named PL/SQL block  A function has a header and a body  Must always return a value (different to a procedure)  If stored on DBMS, we call it stored functions 28 III. Advanced
  • 29. 4. Functions(cont)  Declaration CREATE [OR REPLACE] FUNCTION function_name [parameters] RETURN return_datatype; IS Declaration_section BEGIN Execution_section Return return_variable; EXCEPTION exception section Return return_variable; END; 29 III. Advanced
  • 30. 4. Functions(cont)  Execution  Since a function returns a value we can assign it to a variable variable_name := function_name;  As a part of a SELECT statement SELECT function_name FROM table;  In a PL/SQL Statements like, dbms_output.put_line(function_name); 30 III. Advanced
  • 31. 4. Functions(cont)  Example CREATE OR REPLACE FUNCTION employer_details_func RETURN VARCHAR(20); IS emp_name VARCHAR(20); BEGIN SELECT first_name INTO emp_name FROM emp_tbl WHERE empID = '100'; RETURN emp_name; END; SELECT employer_details_func FROM dual; 31 III. Advanced
  • 32. 5. Parameters in Procedure, Functions  3 ways to pass parameters  IN-parameters  OUT-parameters  IN OUT-parameters NOTE: If a parameter is not explicitly defined a parameter type, then by default it is an IN type parameter. 32 III. Advanced
  • 33. 5. Parameters in Procedure, Functions  Example CREATE OR REPLACE PROCEDURE emp_name ( p_id IN NUMBER , p_emp_name OUT VARCHAR2(20)) IS BEGIN SELECT first_name INTO p_emp_name FROM emp_tbl WHERE empID = p_id; END; 33 III. Advanced
  • 34. 6. Exception Handling 34 III. Advanced  What is a exception handling?  A feature to handle the Exceptions which occur in a PL/SQL Block  Avoid the source code from exiting abruptly  When an exception occurs a messages which explains its cause is received  3 parts of an PL/SQL exception? • Type of Exception • An Error Code • A message
  • 35. 6. Exception Handling 35 III. Advanced  Structure of Exception Handling EXCEPTION WHEN ex_name1 THEN -- Error handling statements WHEN ex_name2 THEN -- Error handling statements WHEN Others THEN -- Error handling statements
  • 36. 6. Exception Handling 36 III. Advanced  3 types of exception  Named System Exceptions  Unnamed System Exceptions  User-defined Exceptions
  • 37. 6. Exception Handling 37 III. Advanced  Example BEGIN -- Execution section EXCEPTION WHEN NO_DATA_FOUND THEN dbms_output.put_line ('A SELECT...INTO did not return any row.'); END;
  • 38. 7. Triggers  What is a Trigger? A trigger is a pl/sql block structure which is fired when a DML statements like Insert, Delete, Update is executed on a database table. A trigger is triggered automatically when an associated DML statement is executed. 38 III. Advanced
  • 39. 7. Triggers(cont)  How to create a trigger? CREATE [OR REPLACE ] TRIGGER trigger_name {BEFORE | AFTER | INSTEAD OF } {INSERT [OR] | UPDATE [OR] | DELETE} [OF col_name] ON table_name [REFERENCING OLD AS o NEW AS n] [FOR EACH ROW] WHEN (condition) BEGIN --- sql statements END; 39 III. Advanced
  • 40. 7. Triggers(cont)  Example The price of a product changes constantly. It is important to maintain the history of the prices of the products. We can create a trigger to update the 'product_price_history' table when the price of the product is updated in the 'product' table. 1. Create the 'product' table and 'product_price_history' table 40 III. Advanced CREATE TABLE product_price_history (product_id NUMBER(5) ,product_name VARCHAR2(32) ,supplier_name VARCHAR2(32) ,unit_price NUMBER(7,2) ); CREATE TABLE product (product_id NUMBER(5) ,product_name VARCHAR2(32) ,supplier_name VARCHAR2(32) ,unit_price NUMBER(7,2) );
  • 41. 7. Triggers(cont)  Example(cont) 2. Create the price_history_trigger and execute it. 41 III. Advanced CREATE OR REPLACE TRIGGER price_history_trigger BEFORE UPDATE OF unit_price ON product FOR EACH ROW BEGIN INSERT INTO product_price_history VALUES (:old.product_id, :old.product_name, :old.supplier_name, :old.unit_price); END;
  • 42. 7. Triggers(cont)  Example(cont) 3. Lets update the price of a product. -- Once executed, the trigger fires and updates the -- product_price_history' table UPDATE PRODUCT SET unit_price = 800 WHERE product_id = 100 4. If you ROLLBACK the transaction before committing to the database, the data inserted to the table is also rolled back. 42 III. Advanced
  • 43. 7. Triggers(cont)  Types of PL/SQL Triggers  Row level trigger - An event is triggered for each row updated, inserted or deleted  Statement level trigger - An event is triggered for each SQL statement executed  PL/SQL Trigger Execution Hierarchy  BEFORE statement trigger fires first  Next BEFORE row level trigger fires, once for each row affected  Then AFTER row level trigger fires once for each affected row. This events will alternates between BEFORE and AFTER row level triggers  Finally the AFTER statement level trigger fires 43 III. Advanced
  • 44. 7. Triggers(cont)  How To know Information about Triggers.  We can use the data dictionary view 'USER_TRIGGERS' to obtain information about any trigger. DESC USER_TRIGGERS;  This view stores information about header and body of the trigger SELECT * FROM user_triggers WHERE trigger_name = 'trigger_name';  You can drop a trigger using the following command. DROP TRIGGER trigger_name; 44 III. Advanced
  • 45. IV. Conclusion 45 Now, I hope this slide gave you some ideas about working with PL/SQL. Please let me know if there’s any mistake or issue in the tutorial. All comments are welcome. With our position in CTI Vietnam. This amount of knowledge would not be enough for us. There’re many more topics we need to invest our time: performance tuning, data mining, coding convention, best practices, … So, let’s share our knowledge, TOGETHER.
  • 46. V. Reference 46 1. PL/SQL Tutorial from plsql-tutorial.com 2. PL/SQL User's Guide and Reference, Release 2 (9.2), from Oracle 3. Database Interaction with PL/SQL, Jagadish Chatarji (Dev Shed) 4. PL/SQL Code Examples, ACS department, University of Utah 5. Doing SQL from PL/SQL: Best and Worst Practices, Oracle
  • 47. VI. Keywords 47 Below is some keywords not mentioned in this slide. If possible, you should google them. General: Embedded SQL, Native dynamic SQL, The DBMS_Sql API, Name resolution, PL/SQL compiler, bounded and unbounded, oracle hint, materialized view. Cursors: sharable SQL structure, session cursor, ref cursor, cursor variable, strong ref cursor, weak ref cursor, identified cursor, DBMS_Sql numeric cursor. Exception Handling: RAISE_APPLICATION_ERROR, PRAGMA, EXCEPTION_INIT. Triggers: CYCLIC CASCADING, ROLLBACK, INSTEAD OF, REFERENCING OLD.