SlideShare uma empresa Scribd logo
1 de 48
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;
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

Mais conteúdo relacionado

Mais procurados (20)

Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
Introduction to sql
Introduction to sqlIntroduction to sql
Introduction to sql
 
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with ExamplesDML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
DML, DDL, DCL ,DRL/DQL and TCL Statements in SQL with Examples
 
SQL Queries Information
SQL Queries InformationSQL Queries Information
SQL Queries Information
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Unit 4 plsql
Unit 4  plsqlUnit 4  plsql
Unit 4 plsql
 
Trigger
TriggerTrigger
Trigger
 
Triggers
TriggersTriggers
Triggers
 
Constraints In Sql
Constraints In SqlConstraints In Sql
Constraints In Sql
 
SQL Views
SQL ViewsSQL Views
SQL Views
 
Sql subquery
Sql  subquerySql  subquery
Sql subquery
 
Sql queries presentation
Sql queries presentationSql queries presentation
Sql queries presentation
 
Sql and Sql commands
Sql and Sql commandsSql and Sql commands
Sql and Sql commands
 
DDL And DML
DDL And DMLDDL And DML
DDL And DML
 
SQL Queries
SQL QueriesSQL Queries
SQL Queries
 
introdution to SQL and SQL functions
introdution to SQL and SQL functionsintrodution to SQL and SQL functions
introdution to SQL and SQL functions
 
Sql commands
Sql commandsSql commands
Sql commands
 
SQL Overview
SQL OverviewSQL Overview
SQL Overview
 
Including Constraints -Oracle Data base
Including Constraints -Oracle Data base Including Constraints -Oracle Data base
Including Constraints -Oracle Data base
 

Destaque

SharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDaysSharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDaysDennis Hobmaier
 
Carte plateau repas 2016 2017
Carte plateau repas 2016 2017Carte plateau repas 2016 2017
Carte plateau repas 2016 2017dimitri peron
 
Digital marketing (argo)
Digital marketing (argo)Digital marketing (argo)
Digital marketing (argo)Oavis Or
 
Radiographic interpretation
Radiographic interpretationRadiographic interpretation
Radiographic interpretationPrince 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 virtuelleFFFOD
 
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
 

Destaque (20)

Fispace in practice
Fispace in practiceFispace in practice
Fispace in practice
 
Course of life ie CV
Course of life ie CVCourse of life ie CV
Course of life ie CV
 
Z googlem w torebce
Z googlem w torebceZ googlem w torebce
Z googlem w torebce
 
BLAZAR
BLAZAR BLAZAR
BLAZAR
 
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
 
SharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDaysSharePoint Governance - Jetzt mit Struktur @CollabDays
SharePoint Governance - Jetzt mit Struktur @CollabDays
 
Empatia Taperoá
Empatia TaperoáEmpatia Taperoá
Empatia Taperoá
 
Carte plateau repas 2016 2017
Carte plateau repas 2016 2017Carte plateau repas 2016 2017
Carte plateau repas 2016 2017
 
11 Ways To Improve Your Website
11 Ways To Improve Your Website11 Ways To Improve Your Website
11 Ways To Improve Your Website
 
Digital marketing (argo)
Digital marketing (argo)Digital marketing (argo)
Digital marketing (argo)
 
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
 
Dear Mr. Kilmer
Dear Mr. KilmerDear Mr. Kilmer
Dear Mr. Kilmer
 
Dear Mr. Kilmer
Dear Mr. KilmerDear Mr. Kilmer
Dear Mr. Kilmer
 
Radiographic interpretation
Radiographic interpretationRadiographic interpretation
Radiographic interpretation
 
READ IT project
READ IT project READ IT project
READ IT project
 
Dear Mr. Kilmer
Dear Mr. KilmerDear Mr. Kilmer
Dear Mr. Kilmer
 
Manual básico de youtube (2016)
Manual básico de youtube (2016)Manual básico de youtube (2016)
Manual básico de youtube (2016)
 
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
 
Fridea - Pomysły. Magiczny wzór.
Fridea - Pomysły. Magiczny wzór.Fridea - Pomysły. Magiczny wzór.
Fridea - Pomysły. Magiczny wzór.
 
Exposición digital
Exposición digital Exposición digital
Exposición digital
 

Semelhante a 4. plsql

plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....Abhiram Vijay
 
Stored procedures
Stored proceduresStored procedures
Stored proceduresMuksNoor
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5Pranab 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_materialgayaramesh
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 functiondipumaliy
 
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 | iTeknowledgeMasood Khan
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3Belal Arfa
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-onlyAshwin Kumar
 
Overview of c language
Overview of c languageOverview of c language
Overview of c languageshalini392
 

Semelhante a 4. plsql (20)

SQL / PL
SQL / PLSQL / PL
SQL / PL
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
PL_SQL - II.pptx
PL_SQL - II.pptxPL_SQL - II.pptx
PL_SQL - II.pptx
 
4 cursors
4 cursors4 cursors
4 cursors
 
plsql tutorialhub....
plsql tutorialhub....plsql tutorialhub....
plsql tutorialhub....
 
PLSQL.pptx
PLSQL.pptxPLSQL.pptx
PLSQL.pptx
 
Stored procedures
Stored proceduresStored procedures
Stored procedures
 
Pl sql
Pl sqlPl sql
Pl sql
 
Database management system chapter5
Database management system chapter5Database management system chapter5
Database management system chapter5
 
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...
 
Pl sql-ch1
Pl sql-ch1Pl sql-ch1
Pl sql-ch1
 
Unit 4 rdbms study_material
Unit 4  rdbms study_materialUnit 4  rdbms study_material
Unit 4 rdbms study_material
 
Rdbms chapter 1 function
Rdbms chapter 1 functionRdbms chapter 1 function
Rdbms chapter 1 function
 
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
 
Dynamic websites lec3
Dynamic websites lec3Dynamic websites lec3
Dynamic websites lec3
 
pl_sql.ppt
pl_sql.pptpl_sql.ppt
pl_sql.ppt
 
3963066 pl-sql-notes-only
3963066 pl-sql-notes-only3963066 pl-sql-notes-only
3963066 pl-sql-notes-only
 
Overview of c language
Overview of c languageOverview of c language
Overview of c language
 
Mis4200notes8 2
Mis4200notes8 2Mis4200notes8 2
Mis4200notes8 2
 
Cursors
CursorsCursors
Cursors
 

Mais de Amrit Kaur

File Organization
File OrganizationFile Organization
File OrganizationAmrit Kaur
 
Introduction to transaction processing
Introduction to transaction processingIntroduction to transaction processing
Introduction to transaction processingAmrit Kaur
 
Transaction Processing
Transaction ProcessingTransaction Processing
Transaction ProcessingAmrit Kaur
 
Sample Interview Question
Sample Interview QuestionSample Interview Question
Sample Interview QuestionAmrit Kaur
 
12. oracle database architecture
12. oracle database architecture12. oracle database architecture
12. oracle database architectureAmrit 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 databaseAmrit Kaur
 
9. index and index organized table
9. index and index organized table9. index and index organized table
9. index and index organized tableAmrit Kaur
 
8. transactions
8. transactions8. transactions
8. transactionsAmrit Kaur
 
7. exceptions handling in pl
7. exceptions handling in pl7. exceptions handling in pl
7. exceptions handling in plAmrit Kaur
 
5. stored procedure and functions
5. stored procedure and functions5. stored procedure and functions
5. stored procedure and functionsAmrit Kaur
 
2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATE2. DML_INSERT_DELETE_UPDATE
2. DML_INSERT_DELETE_UPDATEAmrit Kaur
 
1. dml select statement reterive data
1. dml select statement reterive data1. dml select statement reterive data
1. dml select statement reterive dataAmrit Kaur
 
Chapter 8 Inheritance
Chapter 8 InheritanceChapter 8 Inheritance
Chapter 8 InheritanceAmrit Kaur
 
Chapter 7 C++ As OOP
Chapter 7 C++ As OOPChapter 7 C++ As OOP
Chapter 7 C++ As OOPAmrit Kaur
 
Chapter 6 OOPS Concept
Chapter 6 OOPS ConceptChapter 6 OOPS Concept
Chapter 6 OOPS ConceptAmrit Kaur
 

Mais de Amrit Kaur (20)

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

Último

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxthorishapillay1
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatYousafMalik24
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Celine George
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxChelloAnnAsuncion2
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...JhezDiaz1
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersSabitha Banu
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxiammrhaywood
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPCeline George
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for BeginnersSabitha Banu
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceSamikshaHamane
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfSpandanaRallapalli
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptxmary850239
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSJoshuaGantuangco2
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxAnupkumar Sharma
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxCarlos105
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPCeline George
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️9953056974 Low Rate Call Girls In Saket, Delhi NCR
 

Último (20)

Proudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptxProudly South Africa powerpoint Thorisha.pptx
Proudly South Africa powerpoint Thorisha.pptx
 
Earth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice greatEarth Day Presentation wow hello nice great
Earth Day Presentation wow hello nice great
 
Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17Field Attribute Index Feature in Odoo 17
Field Attribute Index Feature in Odoo 17
 
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptxGrade 9 Q4-MELC1-Active and Passive Voice.pptx
Grade 9 Q4-MELC1-Active and Passive Voice.pptx
 
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
ENGLISH 7_Q4_LESSON 2_ Employing a Variety of Strategies for Effective Interp...
 
DATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginnersDATA STRUCTURE AND ALGORITHM for beginners
DATA STRUCTURE AND ALGORITHM for beginners
 
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptxECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
ECONOMIC CONTEXT - PAPER 1 Q3: NEWSPAPERS.pptx
 
OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...OS-operating systems- ch04 (Threads) ...
OS-operating systems- ch04 (Threads) ...
 
How to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERPHow to do quick user assign in kanban in Odoo 17 ERP
How to do quick user assign in kanban in Odoo 17 ERP
 
Full Stack Web Development Course for Beginners
Full Stack Web Development Course  for BeginnersFull Stack Web Development Course  for Beginners
Full Stack Web Development Course for Beginners
 
Roles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in PharmacovigilanceRoles & Responsibilities in Pharmacovigilance
Roles & Responsibilities in Pharmacovigilance
 
ACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdfACC 2024 Chronicles. Cardiology. Exam.pdf
ACC 2024 Chronicles. Cardiology. Exam.pdf
 
4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx4.18.24 Movement Legacies, Reflection, and Review.pptx
4.18.24 Movement Legacies, Reflection, and Review.pptx
 
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTSGRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
GRADE 4 - SUMMATIVE TEST QUARTER 4 ALL SUBJECTS
 
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptxMULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
MULTIDISCIPLINRY NATURE OF THE ENVIRONMENTAL STUDIES.pptx
 
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptxBarangay Council for the Protection of Children (BCPC) Orientation.pptx
Barangay Council for the Protection of Children (BCPC) Orientation.pptx
 
What is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERPWhat is Model Inheritance in Odoo 17 ERP
What is Model Inheritance in Odoo 17 ERP
 
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptxFINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
FINALS_OF_LEFT_ON_C'N_EL_DORADO_2024.pptx
 
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptxYOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
YOUVE GOT EMAIL_FINALS_EL_DORADO_2024.pptx
 
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
call girls in Kamla Market (DELHI) 🔝 >༒9953330565🔝 genuine Escort Service 🔝✔️✔️
 

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;
  • 30.
  • 31.
  • 32.
  • 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