SlideShare a Scribd company logo
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).
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.
What are Cursors?
•

A cursor is a temporary work area created in the system memory when a SQL
statement is executed. A cursor contains information on a select statement and
the rows of data accessed by it.

•

This temporary work area is used to store the data retrieved from the database,
and manipulate this data. A cursor can hold more than one row, but can process
only one row at a time. The set of rows the cursor holds is called the active set.
There are two types of cursors in PL/SQL:
•

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.

•

Explicit cursors

•

They must be created when you are executing a SELECT statement that returns
more than one row. Even though the cursor stores multiple records, only one
record can be processed at a time, which is called as current row. When you
fetch a row the current row position moves to next row.
Implicit Cursors: Application
•

When you execute DML statements like DELETE, INSERT, UPDATE and
SELECT statements, implicit statements are created to process these
statements.

•

Oracle provides few attributes called as implicit cursor attributes to check the
status of DML operations. The cursor attributes available are %FOUND,
%NOTFOUND, %ROWCOUNT, and %ISOPEN.

•

For example, When you execute INSERT, UPDATE, or DELETE statements the
cursor attributes tell us whether any rows are affected and how many have been
affected.
When a SELECT... INTO statement is executed in a PL/SQL Block, implicit
cursor attributes can be used to find out whether any row has been returned by
the SELECT statement. PL/SQL returns an error when no data is selected.
plsql tutorialhub....
PL/SQL Functions
•

What is a Function in PL/SQL?
•

A function is a named PL/SQL Block which is similar to a procedure. The major
difference between a procedure and a function is, a function must always return
a value, but a procedure may or may not return a value.
Fun() example
•

1) Return Type: The header section defines the return type of the function. The
return datatype can be any of the oracle datatype like varchar, number etc.
2) The execution and exception section both should return a value which is of
the datatype defined in the header section.
Fun2() example
•

In the example we are retrieving the ‘first_name’ of employee with empID 100 to
variable ‘emp_name’.
The return type of the function is VARCHAR which is declared in line no 2.
The function returns the 'emp_name' which is of type VARCHAR as the return
value in line no 9.
How to execute a PL/SQL Function?
A function can be executed in the following ways.

1) Since a function returns a value we can assign it to a variable.

employee_name := employer_details_func;
If ‘employee_name’ is of datatype varchar we can store the name of the employee
by assigning the return type of the function to it.
2) As a part of a SELECT statement
SELECT employer_details_func FROM dual;

3) In a PL/SQL Statements like,
dbms_output.put_line(employer_details_func);
This line displays the value returned by the function.
Explicit Cursors
•

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.

•

Ex:CURSOR cursor_name IS select_statement;

•

cursor_name – A suitable name for the cursor.

•

select_statement – A select query which returns multiple
rows.
How to use Explicit Cursor?
•

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.
Declaring a Cursor in the Declaration
Section:
•

DECLARE CURSOR emp_cur IS SELECT * FROM emp_tbl WHERE salary >
5000;

•

In the above example we are creating a cursor ‘emp_cur’ on a query which
returns the records of all the
employees with salary greater than 5000. Here ‘emp_tbl’ in the table which
contains records of all the
employees.

•

.
2) Accessing the records in the cursor:
•

Once the cursor is created in the declaration section we can access the
cursor in the execution
section of the PL/SQL program
How to access an Explicit Cursor?

These are the three steps in accessing the cursor.

1) Open the cursor.
2) Fetch the records in the cursor one at a time.
3) Close the cursor.
General Syntax to open a cursor is:
OPEN cursor_name;

General Syntax to fetch records from a cursor is:
FETCH cursor_name INTO record_name;
FETCH cursor_name INTO variable_list;

General Syntax to close a cursor is:

CLOSE cursor_name;

OR
•

When a cursor is opened, the first row becomes the current row. When the data is fetched it is
copied to the record or variables and the logical pointer moves to the next row and it becomes
the current row. On every fetch statement, the pointer moves to the next row. If you want to
fetch after the last row, the program will throw an error. When there is more than one row in a
cursor we can use loops along with explicit cursor attributes to fetch all the records.

•

Points to remember while fetching a row:

•

· We can fetch the rows in a cursor to a PL/SQL Record or a list of variables created in the
PL/SQL Block.
· If you are fetching a cursor to a PL/SQL Record, the record should have the same structure as
the cursor.
· If you are fetching a cursor to a list of variables, the variables should be listed in the same
order in the fetch statement as the columns are present in the cursor.
General form:
plsql tutorialhub....
•

In the above example, first we are creating a record ‘emp_rec’ of the same
structure as of table ‘emp_tbl’ in line no 2. We can also create a record with a
cursor by replacing the table name with the cursor name. Second, we are
declaring a cursor ‘emp_cur’ from a select query in line no 3 - 6. Third, we are
opening the cursor in the execution section in line no 8. Fourth, we are fetching
the cursor to the record in line no 9. Fifth, we are displaying the first_name and
last_name of the employee in the record emp_rec in line no 10. Sixth, we are
closing the cursor in line no 11.
•

Using Loops with Explicit Cursors:

•

Oracle provides three types of cursors namely SIMPLE LOOP, WHILE LOOP
and FOR LOOP. These loops can be used to process multiple rows in the
cursor. Here I will modify the same example for each loops to explain how to
use loops with cursors.
plsql tutorialhub....
•

In the above example we are using two cursor attributes %ISOPEN and
%NOTFOUND.
In line no 6, we are using the cursor attribute %ISOPEN to check if the cursor is
open, if the condition is true the program does not open the cursor again, it
directly moves to line no 9.
In line no 11, we are using the cursor attribute %NOTFOUND to check whether
the fetch returned any row. If there is no rows found the program would exit, a
condition which exists when you fetch the cursor after the last row, if there is a
row found the program continues.

•

We can use %FOUND in place of %NOTFOUND and vice versa. If we do so, we
need to reverse the logic of the program. So use these attributes in appropriate
instances.
Ad

More Related Content

What's hot (20)

PL-SQL, Cursors & Triggers
PL-SQL, Cursors & TriggersPL-SQL, Cursors & Triggers
PL-SQL, Cursors & Triggers
Shalabh Chaudhary
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
bunny0143
 
Chapter8 pl sql
Chapter8 pl sqlChapter8 pl sql
Chapter8 pl sql
Jafar Nesargi
 
oracle plsql training | oracle online training | oracle plsql demo | oracle p...
oracle plsql training | oracle online training | oracle plsql demo | oracle p...oracle plsql training | oracle online training | oracle plsql demo | oracle p...
oracle plsql training | oracle online training | oracle plsql demo | oracle p...
Nancy Thomas
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
mohdoracle
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
Ashwin Kumar
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Pl sql-ch1
Pl sql-ch1Pl sql-ch1
Pl sql-ch1
Mukesh Tekwani
 
Oracle: Control Structures
Oracle: Control StructuresOracle: Control Structures
Oracle: Control Structures
DataminingTools Inc
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Srinimf-Slides
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 
Pl sql-ch3
Pl sql-ch3Pl sql-ch3
Pl sql-ch3
Mukesh Tekwani
 
SQL
SQLSQL
SQL
kaushal123
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
Pooja Dixit
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
Arun Sial
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
Plsql
PlsqlPlsql
Plsql
fika sweety
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
Kailash N
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
Vaibhav Kathuria
 
Oracle etl openworld
Oracle etl openworldOracle etl openworld
Oracle etl openworld
Rodrigo Bastos
 
Oracle Baisc Tutorial
Oracle Baisc TutorialOracle Baisc Tutorial
Oracle Baisc Tutorial
bunny0143
 
oracle plsql training | oracle online training | oracle plsql demo | oracle p...
oracle plsql training | oracle online training | oracle plsql demo | oracle p...oracle plsql training | oracle online training | oracle plsql demo | oracle p...
oracle plsql training | oracle online training | oracle plsql demo | oracle p...
Nancy Thomas
 
ORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERSORACLE PL SQL FOR BEGINNERS
ORACLE PL SQL FOR BEGINNERS
mohdoracle
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
Ashwin Kumar
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
Srinimf-Slides
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
Pooja Dixit
 
PLSQL CURSOR
PLSQL CURSORPLSQL CURSOR
PLSQL CURSOR
Arun Sial
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
Kailash N
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
Vaibhav Kathuria
 

Similar to plsql tutorialhub.... (20)

SQL / PL
SQL / PLSQL / PL
SQL / PL
srijanani2030
 
Lecture Notes Unit5 chapter19 Cursor in Pl/SQL
Lecture Notes Unit5 chapter19 Cursor  in Pl/SQLLecture Notes Unit5 chapter19 Cursor  in Pl/SQL
Lecture Notes Unit5 chapter19 Cursor in Pl/SQL
Murugan146644
 
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdfPROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
rajeswaria21
 
Cursors.ppt
Cursors.pptCursors.ppt
Cursors.ppt
Karthick Panneerselvam
 
Oracle:Cursors
Oracle:CursorsOracle:Cursors
Oracle:Cursors
oracle content
 
Oracle: Cursors
Oracle: CursorsOracle: Cursors
Oracle: Cursors
DataminingTools Inc
 
Procedures andcursors
Procedures andcursorsProcedures andcursors
Procedures andcursors
LakshmiSamivel
 
Cursors in oracle
Cursors in oracleCursors in oracle
Cursors in oracle
Tamizhmuhil
 
Les21[1]Writing Explicit Cursors
Les21[1]Writing Explicit CursorsLes21[1]Writing Explicit Cursors
Les21[1]Writing Explicit Cursors
siavosh kaviani
 
PL SQL.pptx in computer language in database
PL SQL.pptx in computer language in databasePL SQL.pptx in computer language in database
PL SQL.pptx in computer language in database
ironman82715
 
Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06
Thuan Nguyen
 
PL/SQL CURSORES
PL/SQL CURSORESPL/SQL CURSORES
PL/SQL CURSORES
Richard Eliseo Mendoza Gafaro
 
PL_SQL - II.pptx
PL_SQL - II.pptxPL_SQL - II.pptx
PL_SQL - II.pptx
priyaprakash11
 
PLSQL (1).ppt
PLSQL (1).pptPLSQL (1).ppt
PLSQL (1).ppt
MadhuriAnaparthy
 
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
suresh
 
Day 6.pptx
Day 6.pptxDay 6.pptx
Day 6.pptx
atreesgalaxy
 
Basic cursors in oracle
Basic cursors in oracleBasic cursors in oracle
Basic cursors in oracle
Suhel Firdus
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
 
Cursors
CursorsCursors
Cursors
Priyanka Yadav
 
Lecture Notes Unit5 chapter19 Cursor in Pl/SQL
Lecture Notes Unit5 chapter19 Cursor  in Pl/SQLLecture Notes Unit5 chapter19 Cursor  in Pl/SQL
Lecture Notes Unit5 chapter19 Cursor in Pl/SQL
Murugan146644
 
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdfPROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
rajeswaria21
 
Cursors in oracle
Cursors in oracleCursors in oracle
Cursors in oracle
Tamizhmuhil
 
Les21[1]Writing Explicit Cursors
Les21[1]Writing Explicit CursorsLes21[1]Writing Explicit Cursors
Les21[1]Writing Explicit Cursors
siavosh kaviani
 
PL SQL.pptx in computer language in database
PL SQL.pptx in computer language in databasePL SQL.pptx in computer language in database
PL SQL.pptx in computer language in database
ironman82715
 
Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06
Thuan Nguyen
 
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
suresh
 
Basic cursors in oracle
Basic cursors in oracleBasic cursors in oracle
Basic cursors in oracle
Suhel Firdus
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 
Loop in C Properties & Applications
Loop in C Properties & ApplicationsLoop in C Properties & Applications
Loop in C Properties & Applications
Emroz Sardar
 
Ad

Recently uploaded (20)

E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
The History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptxThe History of Kashmir Karkota Dynasty NEP.pptx
The History of Kashmir Karkota Dynasty NEP.pptx
Arya Mahila P. G. College, Banaras Hindu University, Varanasi, India.
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
E-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26ASE-Filing_of_Income_Tax.pptx and concept of form 26AS
E-Filing_of_Income_Tax.pptx and concept of form 26AS
Abinash Palangdar
 
Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)Myasthenia gravis (Neuromuscular disorder)
Myasthenia gravis (Neuromuscular disorder)
Mohamed Rizk Khodair
 
How to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo SlidesHow to Create Kanban View in Odoo 18 - Odoo Slides
How to Create Kanban View in Odoo 18 - Odoo Slides
Celine George
 
What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)What is the Philosophy of Statistics? (and how I was drawn to it)
What is the Philosophy of Statistics? (and how I was drawn to it)
jemille6
 
puzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tensepuzzle Irregular Verbs- Simple Past Tense
puzzle Irregular Verbs- Simple Past Tense
OlgaLeonorTorresSnch
 
All About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdfAll About the 990 Unlocking Its Mysteries and Its Power.pdf
All About the 990 Unlocking Its Mysteries and Its Power.pdf
TechSoup
 
Search Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo SlidesSearch Matching Applicants in Odoo 18 - Odoo Slides
Search Matching Applicants in Odoo 18 - Odoo Slides
Celine George
 
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
MCQ PHYSIOLOGY II (DR. NASIR MUSTAFA) MCQS)
Dr. Nasir Mustafa
 
How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18How to Share Accounts Between Companies in Odoo 18
How to Share Accounts Between Companies in Odoo 18
Celine George
 
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales moduleHow To Maximize Sales Performance using Odoo 18 Diverse views in sales module
How To Maximize Sales Performance using Odoo 18 Diverse views in sales module
Celine George
 
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptxANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
ANTI-VIRAL DRUGS unit 3 Pharmacology 3.pptx
Mayuri Chavan
 
Overview Well-Being and Creative Careers
Overview Well-Being and Creative CareersOverview Well-Being and Creative Careers
Overview Well-Being and Creative Careers
University of Amsterdam
 
Module 1: Foundations of Research
Module 1: Foundations of ResearchModule 1: Foundations of Research
Module 1: Foundations of Research
drroxannekemp
 
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Redesigning Education as a Cognitive Ecosystem: Practical Insights into Emerg...
Leonel Morgado
 
UPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guideUPMVLE migration to ARAL. A step- by- step guide
UPMVLE migration to ARAL. A step- by- step guide
abmerca
 
Origin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theoriesOrigin of Brahmi script: A breaking down of various theories
Origin of Brahmi script: A breaking down of various theories
PrachiSontakke5
 
Final Evaluation.docx...........................
Final Evaluation.docx...........................Final Evaluation.docx...........................
Final Evaluation.docx...........................
l1bbyburrell
 
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFAMEDICAL BIOLOGY MCQS  BY. DR NASIR MUSTAFA
MEDICAL BIOLOGY MCQS BY. DR NASIR MUSTAFA
Dr. Nasir Mustafa
 
Cultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptxCultivation Practice of Onion in Nepal.pptx
Cultivation Practice of Onion in Nepal.pptx
UmeshTimilsina1
 
Ad

plsql tutorialhub....

  • 1. 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). 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.
  • 2. What are Cursors? • A cursor is a temporary work area created in the system memory when a SQL statement is executed. A cursor contains information on a select statement and the rows of data accessed by it. • This temporary work area is used to store the data retrieved from the database, and manipulate this data. A cursor can hold more than one row, but can process only one row at a time. The set of rows the cursor holds is called the active set.
  • 3. There are two types of cursors in PL/SQL: • 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. • Explicit cursors • They must be created when you are executing a SELECT statement that returns more than one row. Even though the cursor stores multiple records, only one record can be processed at a time, which is called as current row. When you fetch a row the current row position moves to next row.
  • 4. Implicit Cursors: Application • When you execute DML statements like DELETE, INSERT, UPDATE and SELECT statements, implicit statements are created to process these statements. • Oracle provides few attributes called as implicit cursor attributes to check the status of DML operations. The cursor attributes available are %FOUND, %NOTFOUND, %ROWCOUNT, and %ISOPEN. • For example, When you execute INSERT, UPDATE, or DELETE statements the cursor attributes tell us whether any rows are affected and how many have been affected. When a SELECT... INTO statement is executed in a PL/SQL Block, implicit cursor attributes can be used to find out whether any row has been returned by the SELECT statement. PL/SQL returns an error when no data is selected.
  • 6. PL/SQL Functions • What is a Function in PL/SQL? • A function is a named PL/SQL Block which is similar to a procedure. The major difference between a procedure and a function is, a function must always return a value, but a procedure may or may not return a value.
  • 8. • 1) Return Type: The header section defines the return type of the function. The return datatype can be any of the oracle datatype like varchar, number etc. 2) The execution and exception section both should return a value which is of the datatype defined in the header section.
  • 10. • In the example we are retrieving the ‘first_name’ of employee with empID 100 to variable ‘emp_name’. The return type of the function is VARCHAR which is declared in line no 2. The function returns the 'emp_name' which is of type VARCHAR as the return value in line no 9.
  • 11. How to execute a PL/SQL Function? A function can be executed in the following ways. 1) Since a function returns a value we can assign it to a variable. employee_name := employer_details_func; If ‘employee_name’ is of datatype varchar we can store the name of the employee by assigning the return type of the function to it. 2) As a part of a SELECT statement SELECT employer_details_func FROM dual; 3) In a PL/SQL Statements like, dbms_output.put_line(employer_details_func); This line displays the value returned by the function.
  • 12. Explicit Cursors • 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. • Ex:CURSOR cursor_name IS select_statement; • cursor_name – A suitable name for the cursor. • select_statement – A select query which returns multiple rows.
  • 13. How to use Explicit Cursor? • 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.
  • 14. Declaring a Cursor in the Declaration Section: • DECLARE CURSOR emp_cur IS SELECT * FROM emp_tbl WHERE salary > 5000; • In the above example we are creating a cursor ‘emp_cur’ on a query which returns the records of all the employees with salary greater than 5000. Here ‘emp_tbl’ in the table which contains records of all the employees. • .
  • 15. 2) Accessing the records in the cursor: • Once the cursor is created in the declaration section we can access the cursor in the execution section of the PL/SQL program
  • 16. How to access an Explicit Cursor? These are the three steps in accessing the cursor. 1) Open the cursor. 2) Fetch the records in the cursor one at a time. 3) Close the cursor. General Syntax to open a cursor is: OPEN cursor_name; General Syntax to fetch records from a cursor is: FETCH cursor_name INTO record_name; FETCH cursor_name INTO variable_list; General Syntax to close a cursor is: CLOSE cursor_name; OR
  • 17. • When a cursor is opened, the first row becomes the current row. When the data is fetched it is copied to the record or variables and the logical pointer moves to the next row and it becomes the current row. On every fetch statement, the pointer moves to the next row. If you want to fetch after the last row, the program will throw an error. When there is more than one row in a cursor we can use loops along with explicit cursor attributes to fetch all the records. • Points to remember while fetching a row: • · We can fetch the rows in a cursor to a PL/SQL Record or a list of variables created in the PL/SQL Block. · If you are fetching a cursor to a PL/SQL Record, the record should have the same structure as the cursor. · If you are fetching a cursor to a list of variables, the variables should be listed in the same order in the fetch statement as the columns are present in the cursor.
  • 20. • In the above example, first we are creating a record ‘emp_rec’ of the same structure as of table ‘emp_tbl’ in line no 2. We can also create a record with a cursor by replacing the table name with the cursor name. Second, we are declaring a cursor ‘emp_cur’ from a select query in line no 3 - 6. Third, we are opening the cursor in the execution section in line no 8. Fourth, we are fetching the cursor to the record in line no 9. Fifth, we are displaying the first_name and last_name of the employee in the record emp_rec in line no 10. Sixth, we are closing the cursor in line no 11.
  • 21. • Using Loops with Explicit Cursors: • Oracle provides three types of cursors namely SIMPLE LOOP, WHILE LOOP and FOR LOOP. These loops can be used to process multiple rows in the cursor. Here I will modify the same example for each loops to explain how to use loops with cursors.
  • 23. • In the above example we are using two cursor attributes %ISOPEN and %NOTFOUND. In line no 6, we are using the cursor attribute %ISOPEN to check if the cursor is open, if the condition is true the program does not open the cursor again, it directly moves to line no 9. In line no 11, we are using the cursor attribute %NOTFOUND to check whether the fetch returned any row. If there is no rows found the program would exit, a condition which exists when you fetch the cursor after the last row, if there is a row found the program continues. • We can use %FOUND in place of %NOTFOUND and vice versa. If we do so, we need to reverse the logic of the program. So use these attributes in appropriate instances.
  翻译: