SlideShare a Scribd company logo
1 of 12
1 Using ORACLE® Triggers and Cursors
2 Triggers A trigger is a stored procedure that defines an action that the database automatically initiates when some database related event such as INSERT , UPDATE or DELETE occurs. 					          when occurs fires a  The main difference between a procedure and a trigger is that a procedure is executed explicitly from another block via a procedure call with arguments, while a trigger is executed implicitly when the triggering event like the occurrence of a DML-statement as INSERT ,UPDATE or DELETE occurs. Also a trigger does not accept arguments. The Automatic execution of triggers is known as firing of trigger.
3 Need and Types of Triggers Need for triggers: Maintaining complex integrity constraints. Auditing the information in a table by recording the change. Automatically signaling another program about an occurred event. Enforcing complex business rules.
4 Need and Types of Triggers Types of triggers: Row trigger: 	Fired once for every row that is affected. Statement trigger : Fired only once per statement regardless of the number of row 			affected. Before trigger:	Fired before the triggering event occurs. After trigger: 	Fired after the triggering event occurs.
5 Syntax for Triggers SYNTAX : CREATE OR REPLACE TRIGGER trigger_name 	{BEFORE / AFTER }  	{ INSERT / UPDATE / DELETE} ON object_name 	FOR { EACH ROW / EACH STATEMENT} BEGIN 	Statement1… 	….. 	…... END;
6 Example for triggers SYNTAX : CREATE OR REPLACE TRIGGER trig 	AFTER DELETE ON InfoTable 	FOR EACH ROW BEGIN 	INSERT INTO InfoTable VALUES(:old name,NULL,NULL); END; 	Using this trigger , whenever a row from the InfoTable will be deleted the trigger will be fired and the row containing the deleted row’s name will be inserted with other values as NULL which will help us identify later which rows were deleted.
7 NEED FOR CURSORS We cannot use sub-programs of PL/SQL with a simple select statement to retrieve more than one row. If a select statement in a procedure returns more than one row ,Oracle returns an error message since PL/SQL requires a special compatibility to retrieve and process more than one row. 			Oracle processes procedure without error 			Oracle returns error. SELECT statement in procedure returning one row row SELECT statement in procedure returning more than one row row row row
8 CURSOR A PL/SQL cursor is a mechanism that provides a way to select multiple rows of data from the database and then process each row individually inside a PL/SQL program. A cursor is basically an area of memory containing SQL statements and information for processing those statements. A CURSOR is a pointer to the context area. 		CURSOR is 			 		pointing at  		this row1				             CURSOR is  							             pointing at 						             this row2 now 	   The cursor first points at row1 and once it is processed it then advances to row2 	    and so on. row1 row1 row2 row2 row3 row3 row4 row4
9 Types of CURSORS There are two types of cursors: Implicit cursor: Created and used by Oracle for all DML and PL/SQL select statements including those returning only one row. Explicit cursor : Created and used by the programmer for queries that return more than one row.
10 Types of CURSORS SYNTAX: DECLARE CURSOR cursor_name   AS					Cursor Declaration SELECT statement; --  Variable declaration if any; BEGIN OPEN cursor_name; FETCH <cursor_name> INTO <record_list>	 Cursor Body -- data fetched into active data set. CLOSE cursor_name; END;
11 EXAMPLE OF CURSOR DECLARE CURSOR cus AS SELECT * FROM InfoTable; customer  InfoTable%ROWTYPE;	         declare a rowtype variable BEGIN OPEN cus; LOOP FETCH cus into customer;		         Fetch the row into the variable and advance cursor. DBMS_OUTPUT.PUT_LINE(‘name:’||customer.name); DBMS_OUTPUT.PUT_LINE(‘age:’||customer.age); DBMS_OUTPUT.PUT_LINE(‘phone:’||customer.phone); EXIT WHEN cus%NOTFOUND;	        Returns true when all rows have been fetched. END LOOP; CLOSE cus; END;
THANK YOU 12 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit:   www.dataminingtools.net

More Related Content

What's hot (18)

10053 - null is not nothing
10053 - null is not nothing10053 - null is not nothing
10053 - null is not nothing
 
Mysql creating stored function
Mysql  creating stored function Mysql  creating stored function
Mysql creating stored function
 
Not in vs not exists
Not in vs not existsNot in vs not exists
Not in vs not exists
 
Introduction to triggers
Introduction to triggersIntroduction to triggers
Introduction to triggers
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 
8
88
8
 
Lecture02 abap on line
Lecture02 abap on lineLecture02 abap on line
Lecture02 abap on line
 
Introduction to triggers
Introduction to triggersIntroduction to triggers
Introduction to triggers
 
PLSQL Advanced
PLSQL AdvancedPLSQL Advanced
PLSQL Advanced
 
Stored procedure in sql server
Stored procedure in sql serverStored procedure in sql server
Stored procedure in sql server
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Assignment
AssignmentAssignment
Assignment
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Triggers
TriggersTriggers
Triggers
 
Mysqlppt
MysqlpptMysqlppt
Mysqlppt
 
Bca ii dfs u-2 linklist,stack,queue
Bca ii  dfs u-2 linklist,stack,queueBca ii  dfs u-2 linklist,stack,queue
Bca ii dfs u-2 linklist,stack,queue
 
Ado.net by Awais Majeed
Ado.net by Awais MajeedAdo.net by Awais Majeed
Ado.net by Awais Majeed
 

Viewers also liked

Actividad 1 un dia en la vida de
Actividad 1     un dia en la vida deActividad 1     un dia en la vida de
Actividad 1 un dia en la vida deGuillermo Mondragon
 
(아울러) 빅데이터실록 By 박한우
(아울러) 빅데이터실록 By 박한우(아울러) 빅데이터실록 By 박한우
(아울러) 빅데이터실록 By 박한우Han Woo PARK
 
Dennis yu social amplification engine_guide_v5.1_2016_1210
Dennis yu social amplification engine_guide_v5.1_2016_1210Dennis yu social amplification engine_guide_v5.1_2016_1210
Dennis yu social amplification engine_guide_v5.1_2016_1210Vasil Azarov
 
Building and Managing Social Media Collections
Building and Managing Social Media CollectionsBuilding and Managing Social Media Collections
Building and Managing Social Media CollectionsJason Casden
 
Modelo do dossiê 2014 - prêmio escola de qualidade
Modelo do dossiê  2014 - prêmio escola de qualidadeModelo do dossiê  2014 - prêmio escola de qualidade
Modelo do dossiê 2014 - prêmio escola de qualidadeem_raimundofernandes
 
Forgive and forget
Forgive and forgetForgive and forget
Forgive and forgetVSETLVM
 
Marketing management of mushroom and 7 p’s A Presentation By Mr Allah Dad k...
Marketing management  of mushroom and 7 p’s  A Presentation By Mr Allah Dad k...Marketing management  of mushroom and 7 p’s  A Presentation By Mr Allah Dad k...
Marketing management of mushroom and 7 p’s A Presentation By Mr Allah Dad k...Mr.Allah Dad Khan
 

Viewers also liked (13)

Del rosario
Del rosarioDel rosario
Del rosario
 
Receitas PráTicas
Receitas PráTicasReceitas PráTicas
Receitas PráTicas
 
linkinding
linkindinglinkinding
linkinding
 
Actividad 1 un dia en la vida de
Actividad 1     un dia en la vida deActividad 1     un dia en la vida de
Actividad 1 un dia en la vida de
 
(아울러) 빅데이터실록 By 박한우
(아울러) 빅데이터실록 By 박한우(아울러) 빅데이터실록 By 박한우
(아울러) 빅데이터실록 By 박한우
 
Dennis yu social amplification engine_guide_v5.1_2016_1210
Dennis yu social amplification engine_guide_v5.1_2016_1210Dennis yu social amplification engine_guide_v5.1_2016_1210
Dennis yu social amplification engine_guide_v5.1_2016_1210
 
Mangalyaan
MangalyaanMangalyaan
Mangalyaan
 
Building and Managing Social Media Collections
Building and Managing Social Media CollectionsBuilding and Managing Social Media Collections
Building and Managing Social Media Collections
 
Modelo do dossiê 2014 - prêmio escola de qualidade
Modelo do dossiê  2014 - prêmio escola de qualidadeModelo do dossiê  2014 - prêmio escola de qualidade
Modelo do dossiê 2014 - prêmio escola de qualidade
 
Forgive and forget
Forgive and forgetForgive and forget
Forgive and forget
 
Oracle: Programs
Oracle: ProgramsOracle: Programs
Oracle: Programs
 
Marketing management of mushroom and 7 p’s A Presentation By Mr Allah Dad k...
Marketing management  of mushroom and 7 p’s  A Presentation By Mr Allah Dad k...Marketing management  of mushroom and 7 p’s  A Presentation By Mr Allah Dad k...
Marketing management of mushroom and 7 p’s A Presentation By Mr Allah Dad k...
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
 

Similar to Oracle:Cursors

Similar to Oracle:Cursors (20)

3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
SQL / PL
SQL / PLSQL / PL
SQL / PL
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....
 
Triggers n Cursors.ppt
Triggers n Cursors.pptTriggers n Cursors.ppt
Triggers n Cursors.ppt
 
Cursors
CursorsCursors
Cursors
 
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
 
11303 dbms chap_02_triggers (2)
11303 dbms chap_02_triggers (2)11303 dbms chap_02_triggers (2)
11303 dbms chap_02_triggers (2)
 
4 cursors
4 cursors4 cursors
4 cursors
 
PLSQL (1).ppt
PLSQL (1).pptPLSQL (1).ppt
PLSQL (1).ppt
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
 
Intro to tsql unit 13
Intro to tsql   unit 13Intro to tsql   unit 13
Intro to tsql unit 13
 
Cursors.ppt
Cursors.pptCursors.ppt
Cursors.ppt
 
PLSQL.pptx
PLSQL.pptxPLSQL.pptx
PLSQL.pptx
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 
Cursors
CursorsCursors
Cursors
 
My cool new Slideshow!
My cool new Slideshow!My cool new Slideshow!
My cool new Slideshow!
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 

More from oracle content

More from oracle content (10)

Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
 
Oracle : DML
Oracle : DMLOracle : DML
Oracle : DML
 
Oracle: Commands
Oracle: CommandsOracle: Commands
Oracle: Commands
 
Oracle: Control Structures
Oracle:  Control StructuresOracle:  Control Structures
Oracle: Control Structures
 
Oracle: Dw Design
Oracle: Dw DesignOracle: Dw Design
Oracle: Dw Design
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
 
Oracle Warehouse
Oracle WarehouseOracle Warehouse
Oracle Warehouse
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
 
Oracle: New Plsql
Oracle: New PlsqlOracle: New Plsql
Oracle: New Plsql
 
Oracle: Fundamental Of Dw
Oracle: Fundamental Of DwOracle: Fundamental Of Dw
Oracle: Fundamental Of Dw
 

Recently uploaded

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyAlfredo García Lavilla
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationSlibray Presentation
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionDilum Bandara
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024Stephanie Beckett
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfPrecisely
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 

Recently uploaded (20)

Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Commit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easyCommit 2024 - Secret Management made easy
Commit 2024 - Secret Management made easy
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptxThe Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
The Fit for Passkeys for Employee and Consumer Sign-ins: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
Connect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck PresentationConnect Wave/ connectwave Pitch Deck Presentation
Connect Wave/ connectwave Pitch Deck Presentation
 
Advanced Computer Architecture – An Introduction
Advanced Computer Architecture – An IntroductionAdvanced Computer Architecture – An Introduction
Advanced Computer Architecture – An Introduction
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024What's New in Teams Calling, Meetings and Devices March 2024
What's New in Teams Calling, Meetings and Devices March 2024
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdfHyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
Hyperautomation and AI/ML: A Strategy for Digital Transformation Success.pdf
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 

Oracle:Cursors

  • 1. 1 Using ORACLE® Triggers and Cursors
  • 2. 2 Triggers A trigger is a stored procedure that defines an action that the database automatically initiates when some database related event such as INSERT , UPDATE or DELETE occurs. when occurs fires a The main difference between a procedure and a trigger is that a procedure is executed explicitly from another block via a procedure call with arguments, while a trigger is executed implicitly when the triggering event like the occurrence of a DML-statement as INSERT ,UPDATE or DELETE occurs. Also a trigger does not accept arguments. The Automatic execution of triggers is known as firing of trigger.
  • 3. 3 Need and Types of Triggers Need for triggers: Maintaining complex integrity constraints. Auditing the information in a table by recording the change. Automatically signaling another program about an occurred event. Enforcing complex business rules.
  • 4. 4 Need and Types of Triggers Types of triggers: Row trigger: Fired once for every row that is affected. Statement trigger : Fired only once per statement regardless of the number of row affected. Before trigger: Fired before the triggering event occurs. After trigger: Fired after the triggering event occurs.
  • 5. 5 Syntax for Triggers SYNTAX : CREATE OR REPLACE TRIGGER trigger_name {BEFORE / AFTER } { INSERT / UPDATE / DELETE} ON object_name FOR { EACH ROW / EACH STATEMENT} BEGIN Statement1… ….. …... END;
  • 6. 6 Example for triggers SYNTAX : CREATE OR REPLACE TRIGGER trig AFTER DELETE ON InfoTable FOR EACH ROW BEGIN INSERT INTO InfoTable VALUES(:old name,NULL,NULL); END; Using this trigger , whenever a row from the InfoTable will be deleted the trigger will be fired and the row containing the deleted row’s name will be inserted with other values as NULL which will help us identify later which rows were deleted.
  • 7. 7 NEED FOR CURSORS We cannot use sub-programs of PL/SQL with a simple select statement to retrieve more than one row. If a select statement in a procedure returns more than one row ,Oracle returns an error message since PL/SQL requires a special compatibility to retrieve and process more than one row. Oracle processes procedure without error Oracle returns error. SELECT statement in procedure returning one row row SELECT statement in procedure returning more than one row row row row
  • 8. 8 CURSOR A PL/SQL cursor is a mechanism that provides a way to select multiple rows of data from the database and then process each row individually inside a PL/SQL program. A cursor is basically an area of memory containing SQL statements and information for processing those statements. A CURSOR is a pointer to the context area. CURSOR is pointing at this row1 CURSOR is pointing at this row2 now The cursor first points at row1 and once it is processed it then advances to row2 and so on. row1 row1 row2 row2 row3 row3 row4 row4
  • 9. 9 Types of CURSORS There are two types of cursors: Implicit cursor: Created and used by Oracle for all DML and PL/SQL select statements including those returning only one row. Explicit cursor : Created and used by the programmer for queries that return more than one row.
  • 10. 10 Types of CURSORS SYNTAX: DECLARE CURSOR cursor_name AS Cursor Declaration SELECT statement; -- Variable declaration if any; BEGIN OPEN cursor_name; FETCH <cursor_name> INTO <record_list> Cursor Body -- data fetched into active data set. CLOSE cursor_name; END;
  • 11. 11 EXAMPLE OF CURSOR DECLARE CURSOR cus AS SELECT * FROM InfoTable; customer InfoTable%ROWTYPE; declare a rowtype variable BEGIN OPEN cus; LOOP FETCH cus into customer; Fetch the row into the variable and advance cursor. DBMS_OUTPUT.PUT_LINE(‘name:’||customer.name); DBMS_OUTPUT.PUT_LINE(‘age:’||customer.age); DBMS_OUTPUT.PUT_LINE(‘phone:’||customer.phone); EXIT WHEN cus%NOTFOUND; Returns true when all rows have been fetched. END LOOP; CLOSE cus; END;
  • 12. THANK YOU 12 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit: www.dataminingtools.net