SlideShare a Scribd company logo
PL/SQL
What is PL/SQL?
• PL/SQL is a block-structured language.
• A block lets you group logically related
declarations and statements.
What is PL/SQL?
• A PL/SQL block has three parts:
– Optional DECLARATIVE part,
– an executable part, and
– Optional EXCEPTION-HANDLING part.
[Block header]
[DECLARE <constants> <variables> <cursors>]
[BEGIN]
<PL/SQL statements>
[EXCEPTION exception handling routine>]
END;
Types of Block
• Anonymous Block
– Are blocks without header
• Named Block
– Blocks having headers
– Can be either Subprogram or triggers
– Can be compiled separately and stored
permanently in an Oracle database, Ready to be
executed
Variables and Constant
• Must declare a constant or
variable before referencing it in other
statements in a declarative part of the block
• Declaring Variable
variablename datatype[(size)] [:= initial value]
Variables and Constant
• Variable Declaration
– Bound Declaration
• Specify size for a variable
• Example: age NUMBER(2); --store 2 digits
– Unbound Declaration
• Allocate maximum memory allowed for that particular
type
• Example: age NUMBER;
Variables and Constant
• Variable Declaration
– Anchored Declaration
• Variable is declared with another variable or a
table column
• %TYPE is used for anchor declaration.
variablename object%TYPE[:= initial value]
• Example: num1 NUMBER[5];
num2 num%TYPE;
empsal EMPLOYEE.SALARY%TYPE;
Variable and Constant
• Assigning Values to a Variable
– Assignment operator := is used to assign value to a
variable.
variablename:=<value/expression>
• Commenting Your Code
– Single Line Comment: starts with double ‘-’
– Multiple Line Comment: /*...*/
Variables and Constants
• Literal
– It is a simply a value, which is not represented by an
identifier
• Constant
– Named literal is called constant
– Declaring Constant
constant_name CONSTANT datatype[(size)] := initial value]
Example: pi CONSTANT NUMBER:=3.14;
PL/SQL DATATYPES
PL/SQL Datatypes
• Datatype identify type of data and associated
operation for handling it.
• PL/SQL provides
– Scalar types
– Composite types
– Reference types
– LOB types
1.Scalar Types
• It is atomic.
– Not made up of other dataypes.
• It holds a single value, such as a number or
character string.
• Falls into four types
– PL/SQL Number Types
– PL/SQL Character and String Types
– PL/SQL Boolean Types
– PL/SQL Date, Time, and Interval Types
1.Scalar Types
• PL/SQL Number Types
– BINARY_DOUBLE, BINARY_FLOAT, BINARY_INTEGER,
DEC, DECIMAL, DOUBLE PRECISION, FLOAT, INT,
INTEGER, NATURAL, NATURALN, NUMBER, NUMERIC,
PLS_INTEGER, POSITIVE, POSITIVEN, REAL, SIGNTYPE,
SMALLINT
• PL/SQL Character and String Types
– CHAR, CHARACTER, LONG, LONG RAW, NCHAR,
NVARCHAR2, RAW, ROWID, STRING, UROWID,
VARCHAR, VARCHAR2
1.Scalar Types
• PL/SQL Boolean Types
– BOOLEAN
• PL/SQL Date, Time, and Interval Types
– DATE, TIMESTAMP, TIMESTAMP WITH TIMEZONE,
TIMESTAMP WITH LOCAL TIMEZONE, INTERVAL
YEAR TO MONTH, INTERVAL DAY TOSECOND
2. Composite Type
• Made up with other datatypes such as the
elements of an ARRAY, RECORD, or TABLE.
3. Reference Datatypes
• A reference type holds values, called pointers,
that designate other program items.
• Include REF CURSORS and REFs to object
types.
4. LOB Types
• A LOB type holds values, that specify the
location of large objects, such as text blocks or
graphic images, that are stored separately
from other database data.
• LOB types include BFILE, BLOB, CLOB,
and NCLOB
Printing in PL/SQL
• Procedures of DBMS_OUTPUT package is used
– DBMS_OUTPUT.PUT(string)
– DBMS_OUTPUT.PUT_LINE(string)
• Before using this package run the command
– SET SERVEROUTPUT ON
Writing and Executing PL/SQL Program
• Writing
– Write code in Notepad.
– SQL code files have extension .sql
• Executing
– Give following commands
• @ completefilename -OR-
• EXEC completefilename
Example: @d:mycodeaddition
-in the following line type / to execute
PL/SQL CONTROL STRUCTURE
1. Conditional Control Statement IF
Syntax 1:
IF condition
THEN
.....
END IF;
Syntax 2:
IF condition
THEN
.....
ELSE
.....
END IF;
1. Conditional Control Statement IF
Syntax 3:
IF condition
THEN
.....
ELSIF condition
THEN
.....
ELSIF condition
THEN
.....
ELSE
.....
END IF;
2. CASE Statement
• The CASE statement selects one sequence of
statements to execute.
CASE selector
WHEN value THEN ....
WHEN value THEN...
.....
ELSE .....
END CASE;
3. Using LOOP statement
LOOP
statement(s);
END LOOP;
• Force simple to stop using statements
EXIT;
EXIT WHEN <condition>;
4. While Loop
• The WHILE-LOOP statement executes the
statements in the loop body as long as a
condition is true.
WHILE condition
LOOP
sequence_of_statements
END LOOP;
5. FOR Loop
• FOR loops iterate over a specified range of
integers.
• A double dot (..) serves as the range operator
FOR loopvariable IN [REVERSE} lowest..highest
LOOP
<statement(s);
END LOOP;
DATABASE INTERACTION IN PL/SQL
• You can use following SQL statement in
PL/SQL code
– SELECT
– INSERT
– DELETE
– UPDATE
SELECT INTO statement
• SELECT INTO statement is used to store the
result in variable where PL/SQL access it and
manipulate it.
SELECT column_list INTO variable_list
FROM tablename
[WHERE condition]
Example: SELECT empno,salary INTO eno, sal
FROM employee WHERE empno=5;
4. plsql
4. plsql
4. plsql
SELECT INTO statement
• Where would you store data?????
SELECT * INTO ????????
FROM ....
....
• Solution
– Declare variable for each column
– USE records
USING RECORDS
Using RECORDS
• A record is a group of multiple piece of
information, related to one another called
fields.
• Types of Records
– Table Based Records
– Programmer Defined Records
– Cursor Based Records
Table Based Records
• Represents each fields of a table
• %ROWTYPE is used to declared table based
record.
record_name table_name%ROWTYPE;
• Example
emp_rec employee%ROWTYPE;
Table Based Records
• Accessing individual fields using dot(.)
record_name.field_name
Example:
SELECT * INTO emp_rec
FROM employee
WHERE empno=5
dbms_output.put_line(emp_rec.Name);
Programmer Based Record
• TYPE statement is used to defined
programmer defined record.
• Firstly RECORD type is defined with TYPE
statement then declare variable of RECORD
type.
TYPE <typename> IS RECORD
(fields declaration);
Programmer Based Record
• Example
declare
type empType IS RECORD
(eno number, ename varchar(20));
emp_rec empType;
begin
SELECT empno,name INTO emp_rec
....
end;
NOTE
• IF a SELECT INTO statement return more than
one rows, Oracle return ERROR message.
• Solution
– CURSOR
CURSORS IN PL/SQL
PL/SQL Cursor
• Cursor is a mechanism that provides a way to
select multiple rows of data from a table and
then process each row individually inside
PL/SQL block.
• Set of rows returned by multi row query is
called Result Set or Active Set.
– Context Area contain result set.
– Cursor is pointer to this context Area.
Types of Cursor
• Implicit Cursor
– Declared for all DML and SELECT that return one
row
• Explicit Cursor
– Used for queries that return more than one data.
– Declared and named by programmer.
Explicit Cursor
• Four Steps
1. Declare Cursor
• Declared in declaration part
CURSOR cursorname IS select statement
2. Open Cursor
• Activates query and identification of rows satisfy
query
OPEN cursorname;
Explicit Cursor
• Four Steps
3. Fetch Rows
• Retrieves rows individually
FETCH cursorname INTO record_list
4. Close Cursor
• Close the cursor and release the resources
CLOSE cursorname;
Explicit Cursor Attributes
• %NOTFOUND attribute
• %FOUND attribute
• %ROWCOUNT attribute
• %ISOPEN attribute
ADVANTAGES OF PL/SQL
• Support for SQL
• Better Performance
• Higher Productivity
• Full Portable
• Tight Integration with SQL
• Security
Ad

More Related Content

What's hot (20)

SUBQUERIES.pptx
SUBQUERIES.pptxSUBQUERIES.pptx
SUBQUERIES.pptx
RenugadeviR5
 
Sql Constraints
Sql ConstraintsSql Constraints
Sql Constraints
I L0V3 CODING DR
 
View & index in SQL
View & index in SQLView & index in SQL
View & index in SQL
Swapnali Pawar
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
Quang Minh Đoàn
 
SQL Functions and Operators
SQL Functions and OperatorsSQL Functions and Operators
SQL Functions and Operators
Mohan Kumar.R
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Procedures
rehaniltifat
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
DrkhanchanaR
 
SQL Functions
SQL FunctionsSQL Functions
SQL Functions
ammarbrohi
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
Anurag
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
sunanditaAnand
 
set operators.pptx
set operators.pptxset operators.pptx
set operators.pptx
Anusha sivakumar
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
IshaRana14
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
Sachidananda M H
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
Syed Zaid Irshad
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
Hitesh Mohapatra
 
Sql commands
Sql commandsSql commands
Sql commands
Pooja Dixit
 
database language ppt.pptx
database language ppt.pptxdatabase language ppt.pptx
database language ppt.pptx
Anusha sivakumar
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
Wings Interactive
 
Introduction to oracle database (basic concepts)
Introduction to oracle database (basic concepts)Introduction to oracle database (basic concepts)
Introduction to oracle database (basic concepts)
Bilal Arshad
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
sinhacp
 

Viewers also liked (20)

Fispace in practice
Fispace in practiceFispace in practice
Fispace in practice
Francisco Pérez Durán
 
Course of life ie CV
Course of life ie CVCourse of life ie CV
Course of life ie CV
CA ARPIT BANSAL
 
Z googlem w torebce
Z googlem w torebceZ googlem w torebce
Z googlem w torebce
Patrycja Hrabiec-Hojda
 
BLAZAR
BLAZAR BLAZAR
BLAZAR
Mauro Valentino
 
Aula 2 - Curso de Comunicação e Redação Científica
Aula 2 - Curso de Comunicação e Redação Científica Aula 2 - Curso de Comunicação e Redação Científica
Aula 2 - Curso de Comunicação e Redação Científica
BVS Rede de Informação e Conhecimento – SES/SP Centro de Documentação
 
SharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDaysSharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDays
Dennis Hobmaier
 
Empatia Taperoá
Empatia TaperoáEmpatia Taperoá
Empatia Taperoá
Caetano Falcão
 
Carte plateau repas 2016 2017
Carte plateau repas 2016 2017Carte plateau repas 2016 2017
Carte plateau repas 2016 2017
dimitri peron
 
11 Ways To Improve Your Website
11 Ways To Improve Your Website11 Ways To Improve Your Website
11 Ways To Improve Your Website
SpiralClick Web Technologies
 
Digital marketing (argo)
Digital marketing (argo)Digital marketing (argo)
Digital marketing (argo)
Oavis Or
 
Matthews changing cap after 2020 ceps feb 2017
Matthews changing cap after 2020 ceps feb 2017Matthews changing cap after 2020 ceps feb 2017
Matthews changing cap after 2020 ceps feb 2017
Professor Emeritus of European Agricultural Policy, Trinity College Dublin
 
Dear Mr. Kilmer
Dear Mr. KilmerDear Mr. Kilmer
Dear Mr. Kilmer
Sharuliza Saad
 
Dear Mr. Kilmer
Dear Mr. KilmerDear Mr. Kilmer
Dear Mr. Kilmer
Sharuliza Saad
 
Radiographic interpretation
Radiographic interpretationRadiographic interpretation
Radiographic interpretation
Prince Avi
 
READ IT project
READ IT project READ IT project
READ IT project
Michela Tramonti
 
Dear Mr. Kilmer
Dear Mr. KilmerDear Mr. Kilmer
Dear Mr. Kilmer
Sharuliza Saad
 
Manual básico de youtube (2016)
Manual básico de youtube (2016)Manual básico de youtube (2016)
Manual básico de youtube (2016)
Agneta Gallardo
 
Miles, un dispositif collaboratif de formation virtuelle
Miles, un dispositif collaboratif de formation virtuelleMiles, un dispositif collaboratif de formation virtuelle
Miles, un dispositif collaboratif de formation virtuelle
FFFOD
 
Fridea - Pomysły. Magiczny wzór.
Fridea - Pomysły. Magiczny wzór.Fridea - Pomysły. Magiczny wzór.
Fridea - Pomysły. Magiczny wzór.
Michal Owczarek
 
Exposición digital
Exposición digital Exposición digital
Exposición digital
juanalbertogutierrezromero
 
SharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDaysSharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDays
Dennis Hobmaier
 
Carte plateau repas 2016 2017
Carte plateau repas 2016 2017Carte plateau repas 2016 2017
Carte plateau repas 2016 2017
dimitri peron
 
Digital marketing (argo)
Digital marketing (argo)Digital marketing (argo)
Digital marketing (argo)
Oavis Or
 
Radiographic interpretation
Radiographic interpretationRadiographic interpretation
Radiographic interpretation
Prince Avi
 
Manual básico de youtube (2016)
Manual básico de youtube (2016)Manual básico de youtube (2016)
Manual básico de youtube (2016)
Agneta Gallardo
 
Miles, un dispositif collaboratif de formation virtuelle
Miles, un dispositif collaboratif de formation virtuelleMiles, un dispositif collaboratif de formation virtuelle
Miles, un dispositif collaboratif de formation virtuelle
FFFOD
 
Fridea - Pomysły. Magiczny wzór.
Fridea - Pomysły. Magiczny wzór.Fridea - Pomysły. Magiczny wzór.
Fridea - Pomysły. Magiczny wzór.
Michal Owczarek
 
Ad

Similar to 4. plsql (20)

SQL / PL
SQL / PLSQL / PL
SQL / PL
srijanani2030
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
ASHABOOPATHY
 
PL_SQL - II.pptx
PL_SQL - II.pptxPL_SQL - II.pptx
PL_SQL - II.pptx
priyaprakash11
 
4 cursors
4 cursors4 cursors
4 cursors
Babajan Baig
 
Ppt on plssql study aboutnsmsmskskwkwkwkwk
Ppt on plssql study aboutnsmsmskskwkwkwkwkPpt on plssql study aboutnsmsmskskwkwkwkwk
Ppt on plssql study aboutnsmsmskskwkwkwkwk
DrStrange634619
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....
Abhiram Vijay
 
PLSQL.pptx
PLSQL.pptxPLSQL.pptx
PLSQL.pptx
git21is061t
 
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdfPROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
rajeswaria21
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
MuksNoor
 
Pl sql
Pl sqlPl sql
Pl sql
Hitesh Kumar Markam
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5
Pranab Dasgupta
 
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...
rehaniltifat
 
Pl sql-ch1
Pl sql-ch1Pl sql-ch1
Pl sql-ch1
Mukesh Tekwani
 
Unit 4 rdbms study_material
Unit 4  rdbms study_materialUnit 4  rdbms study_material
Unit 4 rdbms study_material
gayaramesh
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 
pl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledgepl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledge
Masood Khan
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
Belal Arfa
 
pl_sql.ppt
pl_sql.pptpl_sql.ppt
pl_sql.ppt
Prabhat106214
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
Ashwin Kumar
 
Ppt on plssql study aboutnsmsmskskwkwkwkwk
Ppt on plssql study aboutnsmsmskskwkwkwkwkPpt on plssql study aboutnsmsmskskwkwkwkwk
Ppt on plssql study aboutnsmsmskskwkwkwkwk
DrStrange634619
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....
Abhiram Vijay
 
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdfPROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
PROCEDURAL LANGUAGE/ STRUCTURED QUERY LANGUAGE.pdf
rajeswaria21
 
PL/SQL Fundamentals I
PL/SQL Fundamentals IPL/SQL Fundamentals I
PL/SQL Fundamentals I
Nick Buytaert
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
MuksNoor
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5
Pranab Dasgupta
 
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...
rehaniltifat
 
Unit 4 rdbms study_material
Unit 4  rdbms study_materialUnit 4  rdbms study_material
Unit 4 rdbms study_material
gayaramesh
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
dipumaliy
 
pl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledgepl/sql online Training|sql online Training | iTeknowledge
pl/sql online Training|sql online Training | iTeknowledge
Masood Khan
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
Belal Arfa
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
Ashwin Kumar
 
Ad

More from Amrit Kaur (20)

File Organization
File OrganizationFile Organization
File Organization
Amrit Kaur
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processing
Amrit Kaur
 
ER diagram
ER diagramER diagram
ER diagram
Amrit Kaur
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction Processing
Amrit Kaur
 
Normalization
NormalizationNormalization
Normalization
Amrit Kaur
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview Question
Amrit Kaur
 
12. oracle database architecture
12. oracle database architecture12. oracle database architecture
12. oracle database architecture
Amrit Kaur
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle database
Amrit Kaur
 
10. timestamp
10. timestamp10. timestamp
10. timestamp
Amrit Kaur
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
Amrit Kaur
 
8. transactions
8. transactions8. transactions
8. transactions
Amrit Kaur
 
7. exceptions handling in pl
7. exceptions handling in pl7. exceptions handling in pl
7. exceptions handling in pl
Amrit Kaur
 
6. triggers
6. triggers6. triggers
6. triggers
Amrit Kaur
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
Amrit Kaur
 
3. ddl create
3. ddl create3. ddl create
3. ddl create
Amrit Kaur
 
2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE
Amrit Kaur
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
Amrit Kaur
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
Amrit Kaur
 
Chapter 6 OOPS Concept
Chapter 6 OOPS ConceptChapter 6 OOPS Concept
Chapter 6 OOPS Concept
Amrit Kaur
 
File Organization
File OrganizationFile Organization
File Organization
Amrit Kaur
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processing
Amrit Kaur
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction Processing
Amrit Kaur
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview Question
Amrit Kaur
 
12. oracle database architecture
12. oracle database architecture12. oracle database architecture
12. oracle database architecture
Amrit Kaur
 
11. using regular expressions with oracle database
11. using regular expressions with oracle database11. using regular expressions with oracle database
11. using regular expressions with oracle database
Amrit Kaur
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized table
Amrit Kaur
 
8. transactions
8. transactions8. transactions
8. transactions
Amrit Kaur
 
7. exceptions handling in pl
7. exceptions handling in pl7. exceptions handling in pl
7. exceptions handling in pl
Amrit Kaur
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functions
Amrit Kaur
 
2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE
Amrit Kaur
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive data
Amrit Kaur
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 Inheritance
Amrit Kaur
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOP
Amrit Kaur
 
Chapter 6 OOPS Concept
Chapter 6 OOPS ConceptChapter 6 OOPS Concept
Chapter 6 OOPS Concept
Amrit Kaur
 

Recently uploaded (20)

SPRING FESTIVITIES - UK AND USA -
SPRING FESTIVITIES - UK AND USA            -SPRING FESTIVITIES - UK AND USA            -
SPRING FESTIVITIES - UK AND USA -
Colégio Santa Teresinha
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Operations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdfOperations Management (Dr. Abdulfatah Salem).pdf
Operations Management (Dr. Abdulfatah Salem).pdf
Arab Academy for Science, Technology and Maritime Transport
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 
Social Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy StudentsSocial Problem-Unemployment .pptx notes for Physiotherapy Students
Social Problem-Unemployment .pptx notes for Physiotherapy Students
DrNidhiAgarwal
 
How to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of saleHow to manage Multiple Warehouses for multiple floors in odoo point of sale
How to manage Multiple Warehouses for multiple floors in odoo point of sale
Celine George
 
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
World war-1(Causes & impacts at a glance) PPT by Simanchala Sarab(BABed,sem-4...
larencebapu132
 
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptxSCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
SCI BIZ TECH QUIZ (OPEN) PRELIMS XTASY 2025.pptx
Ronisha Das
 
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Niamh Lucey, Mary Dunne. Health Sciences Libraries Group (LAI). Lighting the ...
Library Association of Ireland
 
How to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POSHow to Manage Opening & Closing Controls in Odoo 17 POS
How to Manage Opening & Closing Controls in Odoo 17 POS
Celine George
 
Understanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s GuideUnderstanding P–N Junction Semiconductors: A Beginner’s Guide
Understanding P–N Junction Semiconductors: A Beginner’s Guide
GS Virdi
 
To study Digestive system of insect.pptx
To study Digestive system of insect.pptxTo study Digestive system of insect.pptx
To study Digestive system of insect.pptx
Arshad Shaikh
 
New Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptxNew Microsoft PowerPoint Presentation.pptx
New Microsoft PowerPoint Presentation.pptx
milanasargsyan5
 
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 AccountingHow to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
How to Customize Your Financial Reports & Tax Reports With Odoo 17 Accounting
Celine George
 
Presentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem KayaPresentation of the MIPLM subject matter expert Erdem Kaya
Presentation of the MIPLM subject matter expert Erdem Kaya
MIPLM
 
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdfExploring-Substances-Acidic-Basic-and-Neutral.pdf
Exploring-Substances-Acidic-Basic-and-Neutral.pdf
Sandeep Swamy
 
Sinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_NameSinhala_Male_Names.pdf Sinhala_Male_Name
Sinhala_Male_Names.pdf Sinhala_Male_Name
keshanf79
 
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public SchoolsK12 Tableau Tuesday  - Algebra Equity and Access in Atlanta Public Schools
K12 Tableau Tuesday - Algebra Equity and Access in Atlanta Public Schools
dogden2
 
Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025Stein, Hunt, Green letter to Congress April 2025
Stein, Hunt, Green letter to Congress April 2025
Mebane Rash
 
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam SuccessUltimate VMware 2V0-11.25 Exam Dumps for Exam Success
Ultimate VMware 2V0-11.25 Exam Dumps for Exam Success
Mark Soia
 
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Marie Boran Special Collections Librarian Hardiman Library, University of Gal...
Library Association of Ireland
 
Handling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptxHandling Multiple Choice Responses: Fortune Effiong.pptx
Handling Multiple Choice Responses: Fortune Effiong.pptx
AuthorAIDNationalRes
 

4. plsql

  • 2. What is PL/SQL? • PL/SQL is a block-structured language. • A block lets you group logically related declarations and statements.
  • 3. What is PL/SQL? • A PL/SQL block has three parts: – Optional DECLARATIVE part, – an executable part, and – Optional EXCEPTION-HANDLING part. [Block header] [DECLARE <constants> <variables> <cursors>] [BEGIN] <PL/SQL statements> [EXCEPTION exception handling routine>] END;
  • 4. Types of Block • Anonymous Block – Are blocks without header • Named Block – Blocks having headers – Can be either Subprogram or triggers – Can be compiled separately and stored permanently in an Oracle database, Ready to be executed
  • 5. Variables and Constant • Must declare a constant or variable before referencing it in other statements in a declarative part of the block • Declaring Variable variablename datatype[(size)] [:= initial value]
  • 6. Variables and Constant • Variable Declaration – Bound Declaration • Specify size for a variable • Example: age NUMBER(2); --store 2 digits – Unbound Declaration • Allocate maximum memory allowed for that particular type • Example: age NUMBER;
  • 7. Variables and Constant • Variable Declaration – Anchored Declaration • Variable is declared with another variable or a table column • %TYPE is used for anchor declaration. variablename object%TYPE[:= initial value] • Example: num1 NUMBER[5]; num2 num%TYPE; empsal EMPLOYEE.SALARY%TYPE;
  • 8. Variable and Constant • Assigning Values to a Variable – Assignment operator := is used to assign value to a variable. variablename:=<value/expression> • Commenting Your Code – Single Line Comment: starts with double ‘-’ – Multiple Line Comment: /*...*/
  • 9. Variables and Constants • Literal – It is a simply a value, which is not represented by an identifier • Constant – Named literal is called constant – Declaring Constant constant_name CONSTANT datatype[(size)] := initial value] Example: pi CONSTANT NUMBER:=3.14;
  • 11. PL/SQL Datatypes • Datatype identify type of data and associated operation for handling it. • PL/SQL provides – Scalar types – Composite types – Reference types – LOB types
  • 12. 1.Scalar Types • It is atomic. – Not made up of other dataypes. • It holds a single value, such as a number or character string. • Falls into four types – PL/SQL Number Types – PL/SQL Character and String Types – PL/SQL Boolean Types – PL/SQL Date, Time, and Interval Types
  • 13. 1.Scalar Types • PL/SQL Number Types – BINARY_DOUBLE, BINARY_FLOAT, BINARY_INTEGER, DEC, DECIMAL, DOUBLE PRECISION, FLOAT, INT, INTEGER, NATURAL, NATURALN, NUMBER, NUMERIC, PLS_INTEGER, POSITIVE, POSITIVEN, REAL, SIGNTYPE, SMALLINT • PL/SQL Character and String Types – CHAR, CHARACTER, LONG, LONG RAW, NCHAR, NVARCHAR2, RAW, ROWID, STRING, UROWID, VARCHAR, VARCHAR2
  • 14. 1.Scalar Types • PL/SQL Boolean Types – BOOLEAN • PL/SQL Date, Time, and Interval Types – DATE, TIMESTAMP, TIMESTAMP WITH TIMEZONE, TIMESTAMP WITH LOCAL TIMEZONE, INTERVAL YEAR TO MONTH, INTERVAL DAY TOSECOND
  • 15. 2. Composite Type • Made up with other datatypes such as the elements of an ARRAY, RECORD, or TABLE.
  • 16. 3. Reference Datatypes • A reference type holds values, called pointers, that designate other program items. • Include REF CURSORS and REFs to object types.
  • 17. 4. LOB Types • A LOB type holds values, that specify the location of large objects, such as text blocks or graphic images, that are stored separately from other database data. • LOB types include BFILE, BLOB, CLOB, and NCLOB
  • 18. Printing in PL/SQL • Procedures of DBMS_OUTPUT package is used – DBMS_OUTPUT.PUT(string) – DBMS_OUTPUT.PUT_LINE(string) • Before using this package run the command – SET SERVEROUTPUT ON
  • 19. Writing and Executing PL/SQL Program • Writing – Write code in Notepad. – SQL code files have extension .sql • Executing – Give following commands • @ completefilename -OR- • EXEC completefilename Example: @d:mycodeaddition -in the following line type / to execute
  • 21. 1. Conditional Control Statement IF Syntax 1: IF condition THEN ..... END IF; Syntax 2: IF condition THEN ..... ELSE ..... END IF;
  • 22. 1. Conditional Control Statement IF Syntax 3: IF condition THEN ..... ELSIF condition THEN ..... ELSIF condition THEN ..... ELSE ..... END IF;
  • 23. 2. CASE Statement • The CASE statement selects one sequence of statements to execute. CASE selector WHEN value THEN .... WHEN value THEN... ..... ELSE ..... END CASE;
  • 24. 3. Using LOOP statement LOOP statement(s); END LOOP; • Force simple to stop using statements EXIT; EXIT WHEN <condition>;
  • 25. 4. While Loop • The WHILE-LOOP statement executes the statements in the loop body as long as a condition is true. WHILE condition LOOP sequence_of_statements END LOOP;
  • 26. 5. FOR Loop • FOR loops iterate over a specified range of integers. • A double dot (..) serves as the range operator FOR loopvariable IN [REVERSE} lowest..highest LOOP <statement(s); END LOOP;
  • 28. • You can use following SQL statement in PL/SQL code – SELECT – INSERT – DELETE – UPDATE
  • 29. SELECT INTO statement • SELECT INTO statement is used to store the result in variable where PL/SQL access it and manipulate it. SELECT column_list INTO variable_list FROM tablename [WHERE condition] Example: SELECT empno,salary INTO eno, sal FROM employee WHERE empno=5;
  • 33. SELECT INTO statement • Where would you store data????? SELECT * INTO ???????? FROM .... .... • Solution – Declare variable for each column – USE records
  • 35. Using RECORDS • A record is a group of multiple piece of information, related to one another called fields. • Types of Records – Table Based Records – Programmer Defined Records – Cursor Based Records
  • 36. Table Based Records • Represents each fields of a table • %ROWTYPE is used to declared table based record. record_name table_name%ROWTYPE; • Example emp_rec employee%ROWTYPE;
  • 37. Table Based Records • Accessing individual fields using dot(.) record_name.field_name Example: SELECT * INTO emp_rec FROM employee WHERE empno=5 dbms_output.put_line(emp_rec.Name);
  • 38. Programmer Based Record • TYPE statement is used to defined programmer defined record. • Firstly RECORD type is defined with TYPE statement then declare variable of RECORD type. TYPE <typename> IS RECORD (fields declaration);
  • 39. Programmer Based Record • Example declare type empType IS RECORD (eno number, ename varchar(20)); emp_rec empType; begin SELECT empno,name INTO emp_rec .... end;
  • 40. NOTE • IF a SELECT INTO statement return more than one rows, Oracle return ERROR message. • Solution – CURSOR
  • 42. PL/SQL Cursor • Cursor is a mechanism that provides a way to select multiple rows of data from a table and then process each row individually inside PL/SQL block. • Set of rows returned by multi row query is called Result Set or Active Set. – Context Area contain result set. – Cursor is pointer to this context Area.
  • 43. Types of Cursor • Implicit Cursor – Declared for all DML and SELECT that return one row • Explicit Cursor – Used for queries that return more than one data. – Declared and named by programmer.
  • 44. Explicit Cursor • Four Steps 1. Declare Cursor • Declared in declaration part CURSOR cursorname IS select statement 2. Open Cursor • Activates query and identification of rows satisfy query OPEN cursorname;
  • 45. Explicit Cursor • Four Steps 3. Fetch Rows • Retrieves rows individually FETCH cursorname INTO record_list 4. Close Cursor • Close the cursor and release the resources CLOSE cursorname;
  • 46. Explicit Cursor Attributes • %NOTFOUND attribute • %FOUND attribute • %ROWCOUNT attribute • %ISOPEN attribute
  • 48. • Support for SQL • Better Performance • Higher Productivity • Full Portable • Tight Integration with SQL • Security