SlideShare a Scribd company logo
DATABASE MANAGEMENT SYSTEM
ORACLE SQL AND PL/SQL
PART II : Application Using Oracle PL/SQL
Teaching Aid Material
(www.phindia.com/gupta)

Authors invite your valuable feedback and suggestions on the book
pkdasgupta@gmail.com
RadhaKrishna_P@infosys.com
DATABASE MANAGEMENT SYSTEM
ORACLE SQL AND PL/SQL
PART II : Application Using Oracle PL/SQL

CHAPTER 5
Introduction to PL/SQL Programming
CHAPTER 5
Introduction to PL/SQL Programming
1 of 9

Why PL/SQL?


Better Performance



Higher Productivity



Full Portability



Tight Integration with SQL



Security

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
2 of 9

Character Set

Type

Characters

Uppercase, lowercase

A-Z , a-z

Digits

0-9

Mathematical and
punctuation symbols

~ ! @ # % & * ( )_ - + = | [ ] { }: ; ’’ ’ < > ?
/

White space

Space, tab, carriage return

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
3 of 9

PL/SQL Identifiers






Identifiers are used to name PL/SQL objects such as constants,
variables, exceptions, procedures, cursors and reserved words.
Identifiers can be up to 30 characters in length, must start with a
letter and can include dollar sign, an underscore, and a pound sign.
Identifiers are case sensitive and cannot include space, tab or
carriage return. An identifier can be enclosed within double quotes.

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
4 of 9

PL/SQL Literals


Literals are specific values and are not represented by identifiers



Can be character, number or Boolean value



To embed single quotes within a string literal, two single quotes next
to each other may be placed

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
5 of 9

PL/SQL Delimiters


Delimiters are symbols with special meaning to PL/SQL



Used to separate identifiers from each other

Delimiter

Characteristics

--

Single-line comment indicator

/*

*/

Multiline comment delimiter

||

Concatenation operator

..

Range operator

;

Statement terminator

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
6 of 9

PL/SQL Variable
Type
Scalar

Purpose
Numeric

NUMBER(p, s)
The maximum precision is 38 digits

Character

VARCHAR2, CHAR, LONG
CHAR and VARCHAR2 are up to 32767 bytes

Date

Range is between 01-Jan-4712BC and
31-Dec-9999AD

Boolean

Can hold TRUE, FLASE or NULL only

RAW

Similar to CHAR variables
LONG RAW is similar to LONG
LONG RAW can be up to 2 gigabytes

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
7 of 9

PL/SQL Variable
Type
LOB

Purpose
BFILE

File locaters pointing to read only large objects in
operating system files

BLOB

BLOB locaters that point to large binary objects inside
the database

CLOB

CLOB locaters point to large character objects inside
the database

NCLOB

NCLOB locaters point large national character set
objects inside the database

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
8 of 9

NULL




Represents unknown values as NULL values
NULL is never equal to anything
NVL, IS NULL or IS NOT NULL

CONSTANT



Requires an initial value
Value cannot be changed

Page reference in the book: 147-152
CHAPTER 5
Introduction to PL/SQL Programming
9 of 9

Default Value


A variable is assigned a default value of NULL while declaration



Can be initialized by assignment operator (: =)

Page reference in the book: 147-152
CHAPTER 5
PL/SQL Structure
1 of 3

PL/SQL Structure
Declare
Variables, Cursors, Constants
Begin
PL/SQL statements
Exception
Statements for error handling
End;

Page reference in the book: 152-159
CHAPTER 5
PL/SQL Structure
2 of 3

IF Statement


Allows actions based upon conditions



IF statement can also be nested



Three forms of IF statements:
IF … THEN …
IF … THEN … ELSE …
IF … THEN … ELSIF … ELSE ….

Page reference in the book: 152-159
CHAPTER 5
PL/SQL Structure
3 of 3

Loops in PL/SQL


Simple Loop

Loop
PL/SQL statements
Exit Condition
End Loop



For Loop

For variable IN Start..End
PL/SQL Statements
End Loop;



While Loop

While <Condition> Loop
PL/SQL Statements
End Loop

Page reference in the book: 152-159
CHAPTER 5
PL/SQL and Oracle
1 of 10

Scope of a Variable in Nested Block
PL/SQL statements can be nested

SQL Cursor




A cursor is a private SQL work area where all commands
defined in the cursor are executed
There are two types of cursors:


Implicit cursor



Explicit cursor

Page reference in the book: 159-168
CHAPTER 5
PL/SQL and Oracle
2 of 10

Implicit Cursor


It is automatically created and handled by Oracle Server



Support all types of DMLs [Insert/Update/Delete]



Supports SELECT statement that returns only

Explicit Cursor


Needs to be declared explicitly by the programmer



It is handled using cursor-related commands

Page reference in the book: 159-168
CHAPTER 5
PL/SQL and Oracle
3 of 10

INTO Clause





Into clause is mandatory in a PL/SQL program
It is placed between SELECT and FROM clauses
Acts as a container with the associated variable
Query must return only one row

%TYPE Attribute


Used to declare variables that refer to the column

% ROWTYPE Attribute


Represents a row in a table

Page reference in the book: 159-168
CHAPTER 5
PL/SQL and Oracle
4 of 10

Example EX5_1

Page reference in the book: 159-168
CHAPTER 5
PL/SQL and Oracle
5 of 10

EX5_2

Page reference in the book: 159-168
CHAPTER 5
PL/SQL and Oracle
6 of 10

EX5_3

Page reference in the book: 159-168
CHAPTER 5
PL/SQL and Oracle
EX5_5

Page reference in the book: 159-168

7 of 10
CHAPTER 5
PL/SQL and Oracle
8 of 10

EX5_10

Page reference in the book: 159-168
CHAPTER 5
PL/SQL and Oracle
EX5_11

Page reference in the book: 159-168

9 of 10
CHAPTER 5
PL/SQL and Oracle
10 of 10

EX5_12

Page reference in the book: 159-168
CHAPTER 5
Short/ Objective Type Question
Q1. Define identifiers, literals and delimiters in Oracle PL/SQL.
Q2. Explain %TYPE and %ROWTYPE attributes with the help of suitable examples.
Q3. What do you understand by SQL cursors?
Q4. Write a PL/SQL program which will accept three numbers and print the smallest among them.
SQL>@ C:/TTP/Q4
Enter value for a: 12
Enter value for b: 34
Enter value for c: 12
Smallest Number is 12
Q5. Write PL/SQL program using Loop … End Loop, For Loop and While Loop, which will accept integer from
1 to 10 and print factorial. For example, factorial of 5 is 5*4*3*2*1=120.
SQL>@ C:/TTP/Q5
Enter value for i_num: 6
FACTORIAL OF 6 IS 720
CHAPTER 5
Short/Objective Type Question
Q6. Write a PL/SQL program which will accept a number from 1 to 20 and display following the the figure.
SQL>@ C:/TTP/Q8
Enter value for i_num: 10
-- *
---- *
------ *
-------- *
---------- *
------------ *
-------------- *
---------------- *
------------------ *
-------------------- *

Q7.
(a)
(b)
(c)
(d)

The basic programming unit of a PL/SQL code is a
Procedure
Subprogram
Module
Block

Q8.
(a)
(b)
(c)
(d)

Which of the following sections of a PL/SQL program are optional?
Declarative Section
Exception Handler Section
Executable Section
All of these
CHAPTER 5
Home Assignment
WORKOUT
DATABASE MANAGEMENT SYSTEM
ORACLE SQL AND PL/SQL
PART II : Application using Oracle PL/SQL
Periods Proposed – 18
Chapter 5
Introduction to PL/SQL Programming

1 Period [Theory]
1 Period [Practical]

Chapter 6
Oracle Function, Procedure And Package

1 Period [Theory]
1 Period [Practical]

Chapter 7
Oracle Exception Handler and Database Triggers

1 Period [Theory]
1 Period [Practical]

Chapter 8
Implicit and Explicit Cursors

1 Period [Theory]
2 Periods [Practical]

Chapter 9
Advance Cursors

1 Period [Theory]
1 Period [Practical]

Chapter 10
PL/SQL Collection

1 Period [Theory]
1 Period [Practical]

Chapter 11
Oracle Objects and Dynamic SQL

1 Period [Theory]
1 Period [Practical]

Chapter 12
Performance Tuning

2 Period [Theory]
1 Period [Practical]
THE BOOK
The book is organized into three parts to introduce the
theoretical and programming concepts of DBMS. Part I
(Basic Concepts and Oracle SQL) deals with DBMS basic,
software analysis and design, data flow diagram, ER model,
relational algebra, normal forms, SQL queries, functions,
sub‐queries, different types of joins, DCL, DDL, DML, object
constraints and security in Oracle. Part II (Application Using
Oracle PL/SQL) explains PL/SQL basics, functions,
procedures, packages, exception handling, triggers, implicit,
explicit and advanced cursors using suitable examples. This
part also covers advanced concepts related to PL/SQL, such
as collection, records, objects, dynamic SQL and
performance tuning. Part III (Advanced Concepts and
Technologies) elaborates on advanced database concepts
such as query processing, file organization, distributed
architecture, backup, recovery, data warehousing, online
analytical processing and data mining concepts and their
techniques.

KEY FEATURES
 Includes about 300 examples to illustrate the concepts.
 Offers about 400 objective type questions.
 Provides about 100 challenging workouts.

TEACHING AID MATERIAL
Teaching Aid Material for all the chapters is provided on the
website of PHI Learning. Visit www.phindia.com/gupta to
explore the contents.
Visit PHI Learning Center www.phindia.com/gupta and Click on Instructor Resources to
access Teaching Aid Material for all the 18 chapters of the book.

More Related Content

What's hot

Rdbms concepts
Rdbms conceptsRdbms concepts
Rdbms concepts
Shehrevar Davierwala
 
Mca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database modelMca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database model
Rai University
 
Relational database- Fundamentals
Relational database- FundamentalsRelational database- Fundamentals
Relational database- Fundamentals
Mohammed El Hedhly
 
What is data model? And types.
What is data model? And types.What is data model? And types.
What is data model? And types.
774477
 
Dbms models
Dbms modelsDbms models
Dbms models
devgocool
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
Chirag vasava
 
RDBMS concepts
RDBMS conceptsRDBMS concepts
Query Processing, Query Optimization and Transaction
Query Processing, Query Optimization and TransactionQuery Processing, Query Optimization and Transaction
Query Processing, Query Optimization and Transaction
Prabu U
 
D B M S Animate
D B M S AnimateD B M S Animate
D B M S Animate
Indu George
 
Ch1
Ch1Ch1
DBMS
DBMSDBMS
Chapter 7 relation database language
Chapter 7 relation database languageChapter 7 relation database language
Chapter 7 relation database language
Jafar Nesargi
 
Unit 2 rdbms study_material
Unit 2  rdbms study_materialUnit 2  rdbms study_material
Unit 2 rdbms study_material
gayaramesh
 
Dbms
DbmsDbms
Unit1 rdbms study_materials
Unit1 rdbms study_materialsUnit1 rdbms study_materials
Unit1 rdbms study_materials
gayaramesh
 
Ch09
Ch09Ch09
Week 3 Classification of Database Management Systems & Data Modeling
Week 3 Classification of Database Management Systems & Data ModelingWeek 3 Classification of Database Management Systems & Data Modeling
Week 3 Classification of Database Management Systems & Data Modeling
oudesign
 
Comparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented DatabaseComparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented Database
Editor IJMTER
 
Database design
Database designDatabase design
Database design
Jennifer Polack
 
Deductive Databases Presentation
Deductive Databases PresentationDeductive Databases Presentation
Deductive Databases Presentation
Maroun Baydoun
 

What's hot (20)

Rdbms concepts
Rdbms conceptsRdbms concepts
Rdbms concepts
 
Mca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database modelMca ii-dbms- u-ii-the relational database model
Mca ii-dbms- u-ii-the relational database model
 
Relational database- Fundamentals
Relational database- FundamentalsRelational database- Fundamentals
Relational database- Fundamentals
 
What is data model? And types.
What is data model? And types.What is data model? And types.
What is data model? And types.
 
Dbms models
Dbms modelsDbms models
Dbms models
 
Dbms relational model
Dbms relational modelDbms relational model
Dbms relational model
 
RDBMS concepts
RDBMS conceptsRDBMS concepts
RDBMS concepts
 
Query Processing, Query Optimization and Transaction
Query Processing, Query Optimization and TransactionQuery Processing, Query Optimization and Transaction
Query Processing, Query Optimization and Transaction
 
D B M S Animate
D B M S AnimateD B M S Animate
D B M S Animate
 
Ch1
Ch1Ch1
Ch1
 
DBMS
DBMSDBMS
DBMS
 
Chapter 7 relation database language
Chapter 7 relation database languageChapter 7 relation database language
Chapter 7 relation database language
 
Unit 2 rdbms study_material
Unit 2  rdbms study_materialUnit 2  rdbms study_material
Unit 2 rdbms study_material
 
Dbms
DbmsDbms
Dbms
 
Unit1 rdbms study_materials
Unit1 rdbms study_materialsUnit1 rdbms study_materials
Unit1 rdbms study_materials
 
Ch09
Ch09Ch09
Ch09
 
Week 3 Classification of Database Management Systems & Data Modeling
Week 3 Classification of Database Management Systems & Data ModelingWeek 3 Classification of Database Management Systems & Data Modeling
Week 3 Classification of Database Management Systems & Data Modeling
 
Comparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented DatabaseComparison of Relational Database and Object Oriented Database
Comparison of Relational Database and Object Oriented Database
 
Database design
Database designDatabase design
Database design
 
Deductive Databases Presentation
Deductive Databases PresentationDeductive Databases Presentation
Deductive Databases Presentation
 

Viewers also liked

Oracle Warehouse Management System(Oracle WMS)@ERP OCEAN
Oracle Warehouse Management System(Oracle WMS)@ERP OCEANOracle Warehouse Management System(Oracle WMS)@ERP OCEAN
Oracle Warehouse Management System(Oracle WMS)@ERP OCEAN
ERP OCEAN Infotech Pvt Ltd
 
Vault management system_for_central_banks
Vault management system_for_central_banksVault management system_for_central_banks
Vault management system_for_central_banks
Jean-Marc Lepain
 
Ypip3 oracle erp
Ypip3 oracle erpYpip3 oracle erp
Ypip3 oracle erp
zohra110005
 
Using Maven to build Java & Android program
Using Maven to build Java & Android programUsing Maven to build Java & Android program
Using Maven to build Java & Android program
Mu Chun Wang
 
Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)
XPERT INFOTECH
 
Installing java, eclipse and maven
Installing java, eclipse and mavenInstalling java, eclipse and maven
Installing java, eclipse and maven
inTwentyEight Minutes
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
Raghavan Mohan
 
Oracle - Introduction
Oracle - IntroductionOracle - Introduction
Oracle - Introduction
CompleteITProfessional
 
Database management system chapter13
Database management system chapter13Database management system chapter13
Database management system chapter13
Pranab Dasgupta
 
KeyLabsTraining - Courses
KeyLabsTraining - CoursesKeyLabsTraining - Courses
KeyLabsTraining - Courses
Chinna Botla
 
Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)
Robert Scholte
 
Basic Concepts of Financial Accounting
Basic Concepts of Financial AccountingBasic Concepts of Financial Accounting
Basic Concepts of Financial Accounting
Abdullah Kareem
 
Oracle General Ledger
Oracle General LedgerOracle General Ledger
Oracle General Ledger
Dock Den
 
Oracle Architecture
Oracle ArchitectureOracle Architecture
Oracle Architecture
Neeraj Singh
 
Maven university-course
Maven university-courseMaven university-course
Maven university-course
Olivier Lamy
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
maha tce
 
Introduction to Basic Accounting Concept
Introduction to Basic Accounting ConceptIntroduction to Basic Accounting Concept
Introduction to Basic Accounting Concept
Kamrul Hasan
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
Sidney Chen
 
Basic accounting principles
Basic accounting principlesBasic accounting principles
Basic accounting principles
Umar Gul
 
Oracle EPM BI Overview
Oracle EPM BI OverviewOracle EPM BI Overview
Oracle EPM BI Overview
cglylesu
 

Viewers also liked (20)

Oracle Warehouse Management System(Oracle WMS)@ERP OCEAN
Oracle Warehouse Management System(Oracle WMS)@ERP OCEANOracle Warehouse Management System(Oracle WMS)@ERP OCEAN
Oracle Warehouse Management System(Oracle WMS)@ERP OCEAN
 
Vault management system_for_central_banks
Vault management system_for_central_banksVault management system_for_central_banks
Vault management system_for_central_banks
 
Ypip3 oracle erp
Ypip3 oracle erpYpip3 oracle erp
Ypip3 oracle erp
 
Using Maven to build Java & Android program
Using Maven to build Java & Android programUsing Maven to build Java & Android program
Using Maven to build Java & Android program
 
Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)Presenter manual oracle dba (specially for summer interns)
Presenter manual oracle dba (specially for summer interns)
 
Installing java, eclipse and maven
Installing java, eclipse and mavenInstalling java, eclipse and maven
Installing java, eclipse and maven
 
Java, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorialJava, Eclipse, Maven & JSF tutorial
Java, Eclipse, Maven & JSF tutorial
 
Oracle - Introduction
Oracle - IntroductionOracle - Introduction
Oracle - Introduction
 
Database management system chapter13
Database management system chapter13Database management system chapter13
Database management system chapter13
 
KeyLabsTraining - Courses
KeyLabsTraining - CoursesKeyLabsTraining - Courses
KeyLabsTraining - Courses
 
Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)Java9 and the impact on Maven Projects (JFall 2016)
Java9 and the impact on Maven Projects (JFall 2016)
 
Basic Concepts of Financial Accounting
Basic Concepts of Financial AccountingBasic Concepts of Financial Accounting
Basic Concepts of Financial Accounting
 
Oracle General Ledger
Oracle General LedgerOracle General Ledger
Oracle General Ledger
 
Oracle Architecture
Oracle ArchitectureOracle Architecture
Oracle Architecture
 
Maven university-course
Maven university-courseMaven university-course
Maven university-course
 
DBMS lab manual
DBMS lab manualDBMS lab manual
DBMS lab manual
 
Introduction to Basic Accounting Concept
Introduction to Basic Accounting ConceptIntroduction to Basic Accounting Concept
Introduction to Basic Accounting Concept
 
Oracle Basics and Architecture
Oracle Basics and ArchitectureOracle Basics and Architecture
Oracle Basics and Architecture
 
Basic accounting principles
Basic accounting principlesBasic accounting principles
Basic accounting principles
 
Oracle EPM BI Overview
Oracle EPM BI OverviewOracle EPM BI Overview
Oracle EPM BI Overview
 

Similar to Database management system chapter5

PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics Covered
Danish Mehraj
 
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
 
pl_sql.ppt
pl_sql.pptpl_sql.ppt
pl_sql.ppt
Prabhat106214
 
Dbms 2011
Dbms 2011Dbms 2011
Dbms 2011
Atiqa Khan
 
Pl sql chapter 1
Pl sql chapter 1Pl sql chapter 1
Pl sql chapter 1
PrabhatKumar591
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
Kailash N
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
rehaniltifat
 
Pl sql
Pl sqlPl sql
Pl sql
Pl sqlPl sql
Pl sql
Pl sqlPl sql
Oracle Fundamental and PL-SQL.docx
Oracle Fundamental and PL-SQL.docxOracle Fundamental and PL-SQL.docx
Oracle Fundamental and PL-SQL.docx
Chandan Kumar
 
Oracle etl openworld
Oracle etl openworldOracle etl openworld
Oracle etl openworld
Rodrigo Bastos
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
Rumman Ansari
 
Oracle PLSQL Training in Chennai, Tambaram
Oracle PLSQL Training in Chennai, TambaramOracle PLSQL Training in Chennai, Tambaram
Oracle PLSQL Training in Chennai, Tambaram
Radiant Business Solutions
 
Presenter manual oracle D2K (specially for summer interns)
Presenter manual oracle D2K (specially for summer interns)Presenter manual oracle D2K (specially for summer interns)
Presenter manual oracle D2K (specially for summer interns)
XPERT INFOTECH
 
Chapter8 pl sql
Chapter8 pl sqlChapter8 pl sql
Chapter8 pl sql
Jafar Nesargi
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
pooja_123
 
DBMS 2011
DBMS 2011DBMS 2011
DBMS 2011
Atiqa khan
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
Vaibhav Kathuria
 

Similar to Database management system chapter5 (20)

PL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics CoveredPL/SQL Complete Tutorial. All Topics Covered
PL/SQL Complete Tutorial. All Topics Covered
 
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
 
pl_sql.ppt
pl_sql.pptpl_sql.ppt
pl_sql.ppt
 
Dbms 2011
Dbms 2011Dbms 2011
Dbms 2011
 
Pl sql chapter 1
Pl sql chapter 1Pl sql chapter 1
Pl sql chapter 1
 
Introduction to PL/SQL
Introduction to PL/SQLIntroduction to PL/SQL
Introduction to PL/SQL
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
Pl sql
Pl sqlPl sql
Pl sql
 
Pl sql
Pl sqlPl sql
Pl sql
 
Pl sql
Pl sqlPl sql
Pl sql
 
Oracle Fundamental and PL-SQL.docx
Oracle Fundamental and PL-SQL.docxOracle Fundamental and PL-SQL.docx
Oracle Fundamental and PL-SQL.docx
 
Oracle etl openworld
Oracle etl openworldOracle etl openworld
Oracle etl openworld
 
Sql tutorial
Sql tutorialSql tutorial
Sql tutorial
 
Oracle PLSQL Training in Chennai, Tambaram
Oracle PLSQL Training in Chennai, TambaramOracle PLSQL Training in Chennai, Tambaram
Oracle PLSQL Training in Chennai, Tambaram
 
Presenter manual oracle D2K (specially for summer interns)
Presenter manual oracle D2K (specially for summer interns)Presenter manual oracle D2K (specially for summer interns)
Presenter manual oracle D2K (specially for summer interns)
 
Chapter8 pl sql
Chapter8 pl sqlChapter8 pl sql
Chapter8 pl sql
 
Chapter 1
Chapter 1Chapter 1
Chapter 1
 
DBMS 2011
DBMS 2011DBMS 2011
DBMS 2011
 
Cursors, triggers, procedures
Cursors, triggers, proceduresCursors, triggers, procedures
Cursors, triggers, procedures
 

Recently uploaded

Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
ArianaBusciglio
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
Celine George
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
chanes7
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Dr. Vinod Kumar Kanvaria
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
amberjdewit93
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
Israel Genealogy Research Association
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
TechSoup
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
ak6969907
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
History of Stoke Newington
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
camakaiclarkmusic
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
Academy of Science of South Africa
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
Jean Carlos Nunes Paixão
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
Peter Windle
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Akanksha trivedi rama nursing college kanpur.
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
Celine George
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
Priyankaranawat4
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
David Douglas School District
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
Bisnar Chase Personal Injury Attorneys
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
Colégio Santa Teresinha
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
Celine George
 

Recently uploaded (20)

Group Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana BuscigliopptxGroup Presentation 2 Economics.Ariana Buscigliopptx
Group Presentation 2 Economics.Ariana Buscigliopptx
 
How to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRMHow to Manage Your Lost Opportunities in Odoo 17 CRM
How to Manage Your Lost Opportunities in Odoo 17 CRM
 
Digital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments UnitDigital Artifact 1 - 10VCD Environments Unit
Digital Artifact 1 - 10VCD Environments Unit
 
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
Exploiting Artificial Intelligence for Empowering Researchers and Faculty, In...
 
Digital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental DesignDigital Artefact 1 - Tiny Home Environmental Design
Digital Artefact 1 - Tiny Home Environmental Design
 
The Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collectionThe Diamonds of 2023-2024 in the IGRA collection
The Diamonds of 2023-2024 in the IGRA collection
 
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat  Leveraging AI for Diversity, Equity, and InclusionExecutive Directors Chat  Leveraging AI for Diversity, Equity, and Inclusion
Executive Directors Chat Leveraging AI for Diversity, Equity, and Inclusion
 
World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024World environment day ppt For 5 June 2024
World environment day ppt For 5 June 2024
 
The History of Stoke Newington Street Names
The History of Stoke Newington Street NamesThe History of Stoke Newington Street Names
The History of Stoke Newington Street Names
 
CACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdfCACJapan - GROUP Presentation 1- Wk 4.pdf
CACJapan - GROUP Presentation 1- Wk 4.pdf
 
South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)South African Journal of Science: Writing with integrity workshop (2024)
South African Journal of Science: Writing with integrity workshop (2024)
 
Lapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdfLapbook sobre os Regimes Totalitários.pdf
Lapbook sobre os Regimes Totalitários.pdf
 
A Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in EducationA Strategic Approach: GenAI in Education
A Strategic Approach: GenAI in Education
 
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama UniversityNatural birth techniques - Mrs.Akanksha Trivedi Rama University
Natural birth techniques - Mrs.Akanksha Trivedi Rama University
 
How to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP ModuleHow to Add Chatter in the odoo 17 ERP Module
How to Add Chatter in the odoo 17 ERP Module
 
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdfANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
ANATOMY AND BIOMECHANICS OF HIP JOINT.pdf
 
Pride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School DistrictPride Month Slides 2024 David Douglas School District
Pride Month Slides 2024 David Douglas School District
 
Top five deadliest dog breeds in America
Top five deadliest dog breeds in AmericaTop five deadliest dog breeds in America
Top five deadliest dog breeds in America
 
MARY JANE WILSON, A “BOA MÃE” .
MARY JANE WILSON, A “BOA MÃE”           .MARY JANE WILSON, A “BOA MÃE”           .
MARY JANE WILSON, A “BOA MÃE” .
 
How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17How to Fix the Import Error in the Odoo 17
How to Fix the Import Error in the Odoo 17
 

Database management system chapter5

  • 1. DATABASE MANAGEMENT SYSTEM ORACLE SQL AND PL/SQL PART II : Application Using Oracle PL/SQL Teaching Aid Material (www.phindia.com/gupta) Authors invite your valuable feedback and suggestions on the book pkdasgupta@gmail.com RadhaKrishna_P@infosys.com
  • 2. DATABASE MANAGEMENT SYSTEM ORACLE SQL AND PL/SQL PART II : Application Using Oracle PL/SQL CHAPTER 5 Introduction to PL/SQL Programming
  • 3. CHAPTER 5 Introduction to PL/SQL Programming 1 of 9 Why PL/SQL?  Better Performance  Higher Productivity  Full Portability  Tight Integration with SQL  Security Page reference in the book: 147-152
  • 4. CHAPTER 5 Introduction to PL/SQL Programming 2 of 9 Character Set Type Characters Uppercase, lowercase A-Z , a-z Digits 0-9 Mathematical and punctuation symbols ~ ! @ # % & * ( )_ - + = | [ ] { }: ; ’’ ’ < > ? / White space Space, tab, carriage return Page reference in the book: 147-152
  • 5. CHAPTER 5 Introduction to PL/SQL Programming 3 of 9 PL/SQL Identifiers    Identifiers are used to name PL/SQL objects such as constants, variables, exceptions, procedures, cursors and reserved words. Identifiers can be up to 30 characters in length, must start with a letter and can include dollar sign, an underscore, and a pound sign. Identifiers are case sensitive and cannot include space, tab or carriage return. An identifier can be enclosed within double quotes. Page reference in the book: 147-152
  • 6. CHAPTER 5 Introduction to PL/SQL Programming 4 of 9 PL/SQL Literals  Literals are specific values and are not represented by identifiers  Can be character, number or Boolean value  To embed single quotes within a string literal, two single quotes next to each other may be placed Page reference in the book: 147-152
  • 7. CHAPTER 5 Introduction to PL/SQL Programming 5 of 9 PL/SQL Delimiters  Delimiters are symbols with special meaning to PL/SQL  Used to separate identifiers from each other Delimiter Characteristics -- Single-line comment indicator /* */ Multiline comment delimiter || Concatenation operator .. Range operator ; Statement terminator Page reference in the book: 147-152
  • 8. CHAPTER 5 Introduction to PL/SQL Programming 6 of 9 PL/SQL Variable Type Scalar Purpose Numeric NUMBER(p, s) The maximum precision is 38 digits Character VARCHAR2, CHAR, LONG CHAR and VARCHAR2 are up to 32767 bytes Date Range is between 01-Jan-4712BC and 31-Dec-9999AD Boolean Can hold TRUE, FLASE or NULL only RAW Similar to CHAR variables LONG RAW is similar to LONG LONG RAW can be up to 2 gigabytes Page reference in the book: 147-152
  • 9. CHAPTER 5 Introduction to PL/SQL Programming 7 of 9 PL/SQL Variable Type LOB Purpose BFILE File locaters pointing to read only large objects in operating system files BLOB BLOB locaters that point to large binary objects inside the database CLOB CLOB locaters point to large character objects inside the database NCLOB NCLOB locaters point large national character set objects inside the database Page reference in the book: 147-152
  • 10. CHAPTER 5 Introduction to PL/SQL Programming 8 of 9 NULL    Represents unknown values as NULL values NULL is never equal to anything NVL, IS NULL or IS NOT NULL CONSTANT   Requires an initial value Value cannot be changed Page reference in the book: 147-152
  • 11. CHAPTER 5 Introduction to PL/SQL Programming 9 of 9 Default Value  A variable is assigned a default value of NULL while declaration  Can be initialized by assignment operator (: =) Page reference in the book: 147-152
  • 12. CHAPTER 5 PL/SQL Structure 1 of 3 PL/SQL Structure Declare Variables, Cursors, Constants Begin PL/SQL statements Exception Statements for error handling End; Page reference in the book: 152-159
  • 13. CHAPTER 5 PL/SQL Structure 2 of 3 IF Statement  Allows actions based upon conditions  IF statement can also be nested  Three forms of IF statements: IF … THEN … IF … THEN … ELSE … IF … THEN … ELSIF … ELSE …. Page reference in the book: 152-159
  • 14. CHAPTER 5 PL/SQL Structure 3 of 3 Loops in PL/SQL  Simple Loop Loop PL/SQL statements Exit Condition End Loop  For Loop For variable IN Start..End PL/SQL Statements End Loop;  While Loop While <Condition> Loop PL/SQL Statements End Loop Page reference in the book: 152-159
  • 15. CHAPTER 5 PL/SQL and Oracle 1 of 10 Scope of a Variable in Nested Block PL/SQL statements can be nested SQL Cursor   A cursor is a private SQL work area where all commands defined in the cursor are executed There are two types of cursors:  Implicit cursor  Explicit cursor Page reference in the book: 159-168
  • 16. CHAPTER 5 PL/SQL and Oracle 2 of 10 Implicit Cursor  It is automatically created and handled by Oracle Server  Support all types of DMLs [Insert/Update/Delete]  Supports SELECT statement that returns only Explicit Cursor  Needs to be declared explicitly by the programmer  It is handled using cursor-related commands Page reference in the book: 159-168
  • 17. CHAPTER 5 PL/SQL and Oracle 3 of 10 INTO Clause     Into clause is mandatory in a PL/SQL program It is placed between SELECT and FROM clauses Acts as a container with the associated variable Query must return only one row %TYPE Attribute  Used to declare variables that refer to the column % ROWTYPE Attribute  Represents a row in a table Page reference in the book: 159-168
  • 18. CHAPTER 5 PL/SQL and Oracle 4 of 10 Example EX5_1 Page reference in the book: 159-168
  • 19. CHAPTER 5 PL/SQL and Oracle 5 of 10 EX5_2 Page reference in the book: 159-168
  • 20. CHAPTER 5 PL/SQL and Oracle 6 of 10 EX5_3 Page reference in the book: 159-168
  • 21. CHAPTER 5 PL/SQL and Oracle EX5_5 Page reference in the book: 159-168 7 of 10
  • 22. CHAPTER 5 PL/SQL and Oracle 8 of 10 EX5_10 Page reference in the book: 159-168
  • 23. CHAPTER 5 PL/SQL and Oracle EX5_11 Page reference in the book: 159-168 9 of 10
  • 24. CHAPTER 5 PL/SQL and Oracle 10 of 10 EX5_12 Page reference in the book: 159-168
  • 25. CHAPTER 5 Short/ Objective Type Question Q1. Define identifiers, literals and delimiters in Oracle PL/SQL. Q2. Explain %TYPE and %ROWTYPE attributes with the help of suitable examples. Q3. What do you understand by SQL cursors? Q4. Write a PL/SQL program which will accept three numbers and print the smallest among them. SQL>@ C:/TTP/Q4 Enter value for a: 12 Enter value for b: 34 Enter value for c: 12 Smallest Number is 12 Q5. Write PL/SQL program using Loop … End Loop, For Loop and While Loop, which will accept integer from 1 to 10 and print factorial. For example, factorial of 5 is 5*4*3*2*1=120. SQL>@ C:/TTP/Q5 Enter value for i_num: 6 FACTORIAL OF 6 IS 720
  • 26. CHAPTER 5 Short/Objective Type Question Q6. Write a PL/SQL program which will accept a number from 1 to 20 and display following the the figure. SQL>@ C:/TTP/Q8 Enter value for i_num: 10 -- * ---- * ------ * -------- * ---------- * ------------ * -------------- * ---------------- * ------------------ * -------------------- * Q7. (a) (b) (c) (d) The basic programming unit of a PL/SQL code is a Procedure Subprogram Module Block Q8. (a) (b) (c) (d) Which of the following sections of a PL/SQL program are optional? Declarative Section Exception Handler Section Executable Section All of these
  • 28. DATABASE MANAGEMENT SYSTEM ORACLE SQL AND PL/SQL PART II : Application using Oracle PL/SQL Periods Proposed – 18 Chapter 5 Introduction to PL/SQL Programming 1 Period [Theory] 1 Period [Practical] Chapter 6 Oracle Function, Procedure And Package 1 Period [Theory] 1 Period [Practical] Chapter 7 Oracle Exception Handler and Database Triggers 1 Period [Theory] 1 Period [Practical] Chapter 8 Implicit and Explicit Cursors 1 Period [Theory] 2 Periods [Practical] Chapter 9 Advance Cursors 1 Period [Theory] 1 Period [Practical] Chapter 10 PL/SQL Collection 1 Period [Theory] 1 Period [Practical] Chapter 11 Oracle Objects and Dynamic SQL 1 Period [Theory] 1 Period [Practical] Chapter 12 Performance Tuning 2 Period [Theory] 1 Period [Practical]
  • 29. THE BOOK The book is organized into three parts to introduce the theoretical and programming concepts of DBMS. Part I (Basic Concepts and Oracle SQL) deals with DBMS basic, software analysis and design, data flow diagram, ER model, relational algebra, normal forms, SQL queries, functions, sub‐queries, different types of joins, DCL, DDL, DML, object constraints and security in Oracle. Part II (Application Using Oracle PL/SQL) explains PL/SQL basics, functions, procedures, packages, exception handling, triggers, implicit, explicit and advanced cursors using suitable examples. This part also covers advanced concepts related to PL/SQL, such as collection, records, objects, dynamic SQL and performance tuning. Part III (Advanced Concepts and Technologies) elaborates on advanced database concepts such as query processing, file organization, distributed architecture, backup, recovery, data warehousing, online analytical processing and data mining concepts and their techniques. KEY FEATURES  Includes about 300 examples to illustrate the concepts.  Offers about 400 objective type questions.  Provides about 100 challenging workouts. TEACHING AID MATERIAL Teaching Aid Material for all the chapters is provided on the website of PHI Learning. Visit www.phindia.com/gupta to explore the contents.
  • 30. Visit PHI Learning Center www.phindia.com/gupta and Click on Instructor Resources to access Teaching Aid Material for all the 18 chapters of the book.