SlideShare a Scribd company logo
Conditional Statements
Dr.P.Dhanalakshmi
Syntax for IF Statement:
â€ĸ IF condition
â€ĸ THEN
â€ĸ Statement: {It is executed when condition is true}
â€ĸ END IF;
â€ĸ There are different syntaxes for the IF-THEN-ELSE statement.
â€ĸ IF condition
â€ĸ THEN
â€ĸ {...statements to execute when condition is TRUE...}
â€ĸ ELSE
â€ĸ {...statements to execute when condition is FALSE...}
â€ĸ END IF;
â€ĸ Syntax: (IF-THEN-ELSIF statement):
â€ĸ IF condition1
â€ĸ THEN
â€ĸ {...statements to execute when condition1 is TRUE...}
â€ĸ ELSIF condition2
â€ĸ THEN
â€ĸ {...statements to execute when condition2 is TRUE...}
â€ĸ END IF;
Syntax: (IF-THEN-ELSIF-ELSE statement):
â€ĸ IF condition1
â€ĸ THEN
â€ĸ {...statements to execute when condition1 is TRUE...}
â€ĸ ELSIF condition2
â€ĸ THEN
â€ĸ {...statements to execute when condition2 is TRUE...}
â€ĸ ELSE
â€ĸ {...statements to execute when both condition1 and condition2 are FALSE
...}
â€ĸ END IF;
â€ĸ DECLARE
â€ĸ a number(3) := 500;
â€ĸ BEGIN
â€ĸ -- check the boolean condition using if statement
â€ĸ IF( a < 20 ) THEN
â€ĸ -- if condition is true then print the following
â€ĸ dbms_output.put_line('a is less than 20 ' );
â€ĸ ELSE
â€ĸ dbms_output.put_line('a is not less than 20 ' );
â€ĸ END IF;
â€ĸ dbms_output.put_line('value of a is : ' || a);
â€ĸ END;
PL/SQL Function
â€ĸ The PL/SQL Function is very similar to PL/SQL Procedure.
â€ĸ The main difference between procedure and a function is, a function must
always return a value, and on the other hand a procedure may or may not
return a value.
â€ĸ Syntax to create a function:
â€ĸ CREATE [OR REPLACE] FUNCTION function_name [parameters]
â€ĸ [(parameter_name [IN | OUT | IN OUT] type [, ...])]
â€ĸ RETURN return_datatype
â€ĸ {IS | AS}
â€ĸ BEGIN
â€ĸ < function_body >
â€ĸ END [function_name];
â€ĸ Here:
â€ĸ Function_name: specifies the name of the function.
â€ĸ [OR REPLACE] option allows modifying an existing function.
â€ĸ The optional parameter list contains name, mode and types of the
parameters.
â€ĸ IN represents that value will be passed from outside and OUT
represents that this parameter will be used to return a value outside
of the procedure.
â€ĸ The function must contain a return statement.
â€ĸ RETURN clause specifies that data type you are going to return from
the function.
â€ĸ Function_body contains the executable part.
â€ĸ The AS keyword is used instead of the IS keyword for creating a
standalone function.
â€ĸ create or replace function adder(n1 in number, n2 in number)
â€ĸ return number
â€ĸ is
â€ĸ n3 number(8);
â€ĸ begin
â€ĸ n3 :=n1+n2;
â€ĸ return n3;
â€ĸ end;
â€ĸ /
â€ĸ DECLARE
â€ĸ n3 number(2);
â€ĸ BEGIN
â€ĸ n3 := adder(11,22);
â€ĸ dbms_output.put_line('Addition is: ' || n3);
â€ĸ END;
â€ĸ /

More Related Content

PDF
SQL Procedures & Functions
JeevananthamArumugam
 
PDF
Lecture Notes Unit5 chapter 15 PL/SQL Programming
Murugan146644
 
PDF
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
KavitaShinde26
 
PPTX
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
PPT
plsql.ppt
faizan992426
 
PPTX
Procedure n functions
Khadija Parween
 
PPT
SQL / PL
srijanani2030
 
PPTX
pl/sql Procedure
Pooja Dixit
 
SQL Procedures & Functions
JeevananthamArumugam
 
Lecture Notes Unit5 chapter 15 PL/SQL Programming
Murugan146644
 
UNIT 1- RELATIONAL DATABASE DESIGN USING PLSQL.pdf
KavitaShinde26
 
Procedure and Functions in pl/sql
Ñirmal Tatiwal
 
plsql.ppt
faizan992426
 
Procedure n functions
Khadija Parween
 
SQL / PL
srijanani2030
 
pl/sql Procedure
Pooja Dixit
 

Similar to TWO.pptx (20)

PPTX
PLSQL.pptx
git21is061t
 
PPTX
PL SQL.pptx in computer language in database
ironman82715
 
PPT
05 Creating Stored Procedures
rehaniltifat
 
PPT
Les09
um_adeveloper
 
PPTX
Pl sql chapter 2
PrabhatKumar591
 
PPTX
Pl-sql blocks and block types and variablesdeclaring.pptx
abobakralwaylysocial
 
PPTX
Oracle: Control Structures
oracle content
 
PPTX
Oracle: Control Structures
DataminingTools Inc
 
PPTX
Unit 3
Abha Damani
 
PPTX
Advanced DB lab 1 (2).pptx
AdemeCheklie
 
PPTX
PL_SQL_1.pptx fvbxcfbhxdfgh .
RAMIROENRIQUERAMALLO
 
PPTX
9. DBMS Experiment Laboratory PresentationPPT
TheVerse1
 
PPTX
Unit 3(rdbms)
Jay Patel
 
PPTX
Unit 3(rdbms)
Jay Patel
 
PPTX
Rdbms chapter 1 function
dipumaliy
 
PPTX
DBMS: Week 11 - Stored Procedures and Functions
RashidFaridChishti
 
PDF
PL_pgSQL_Control_Structures__An_Introduction.pdf
RezaZulman
 
PPTX
Pl sql Prograaming of Database management system
AjitPatil801582
 
PDF
Dynamic websites lec3
Belal Arfa
 
PDF
Oracle 11G PL SQL Programming 2nd Edition Casteel Solutions Manual
mutorenesen
 
PLSQL.pptx
git21is061t
 
PL SQL.pptx in computer language in database
ironman82715
 
05 Creating Stored Procedures
rehaniltifat
 
Les09
um_adeveloper
 
Pl sql chapter 2
PrabhatKumar591
 
Pl-sql blocks and block types and variablesdeclaring.pptx
abobakralwaylysocial
 
Oracle: Control Structures
oracle content
 
Oracle: Control Structures
DataminingTools Inc
 
Unit 3
Abha Damani
 
Advanced DB lab 1 (2).pptx
AdemeCheklie
 
PL_SQL_1.pptx fvbxcfbhxdfgh .
RAMIROENRIQUERAMALLO
 
9. DBMS Experiment Laboratory PresentationPPT
TheVerse1
 
Unit 3(rdbms)
Jay Patel
 
Unit 3(rdbms)
Jay Patel
 
Rdbms chapter 1 function
dipumaliy
 
DBMS: Week 11 - Stored Procedures and Functions
RashidFaridChishti
 
PL_pgSQL_Control_Structures__An_Introduction.pdf
RezaZulman
 
Pl sql Prograaming of Database management system
AjitPatil801582
 
Dynamic websites lec3
Belal Arfa
 
Oracle 11G PL SQL Programming 2nd Edition Casteel Solutions Manual
mutorenesen
 

Recently uploaded (20)

PDF
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
PDF
Introduction to Data Science: data science process
ShivarkarSandip
 
PPTX
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
PDF
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PPTX
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
PPTX
easa module 3 funtamental electronics.pptx
tryanothert7
 
PPTX
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
PDF
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
PDF
Zero carbon Building Design Guidelines V4
BassemOsman1
 
PPTX
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
PDF
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
PDF
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
PPTX
Inventory management chapter in automation and robotics.
atisht0104
 
PPTX
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
PDF
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
PPT
SCOPE_~1- technology of green house and poyhouse
bala464780
 
PPTX
Information Retrieval and Extraction - Module 7
premSankar19
 
DOCX
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
PDF
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 
Unit I Part II.pdf : Security Fundamentals
Dr. Madhuri Jawale
 
Introduction to Data Science: data science process
ShivarkarSandip
 
Victory Precisions_Supplier Profile.pptx
victoryprecisions199
 
Advanced LangChain & RAG: Building a Financial AI Assistant with Real-Time Data
Soufiane Sejjari
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Module2 Data Base Design- ER and NF.pptx
gomathisankariv2
 
easa module 3 funtamental electronics.pptx
tryanothert7
 
business incubation centre aaaaaaaaaaaaaa
hodeeesite4
 
Top 10 read articles In Managing Information Technology.pdf
IJMIT JOURNAL
 
Zero carbon Building Design Guidelines V4
BassemOsman1
 
MT Chapter 1.pptx- Magnetic particle testing
ABCAnyBodyCanRelax
 
67243-Cooling and Heating & Calculation.pdf
DHAKA POLYTECHNIC
 
Natural_Language_processing_Unit_I_notes.pdf
sanguleumeshit
 
Inventory management chapter in automation and robotics.
atisht0104
 
Chapter_Seven_Construction_Reliability_Elective_III_Msc CM
SubashKumarBhattarai
 
Biodegradable Plastics: Innovations and Market Potential (www.kiu.ac.ug)
publication11
 
SCOPE_~1- technology of green house and poyhouse
bala464780
 
Information Retrieval and Extraction - Module 7
premSankar19
 
SAR - EEEfdfdsdasdsdasdasdasdasdasdasdasda.docx
Kanimozhi676285
 
2010_Book_EnvironmentalBioengineering (1).pdf
EmilianoRodriguezTll
 

TWO.pptx

  • 2. Syntax for IF Statement: â€ĸ IF condition â€ĸ THEN â€ĸ Statement: {It is executed when condition is true} â€ĸ END IF; â€ĸ There are different syntaxes for the IF-THEN-ELSE statement.
  • 3. â€ĸ IF condition â€ĸ THEN â€ĸ {...statements to execute when condition is TRUE...} â€ĸ ELSE â€ĸ {...statements to execute when condition is FALSE...} â€ĸ END IF;
  • 4. â€ĸ Syntax: (IF-THEN-ELSIF statement): â€ĸ IF condition1 â€ĸ THEN â€ĸ {...statements to execute when condition1 is TRUE...} â€ĸ ELSIF condition2 â€ĸ THEN â€ĸ {...statements to execute when condition2 is TRUE...} â€ĸ END IF;
  • 5. Syntax: (IF-THEN-ELSIF-ELSE statement): â€ĸ IF condition1 â€ĸ THEN â€ĸ {...statements to execute when condition1 is TRUE...} â€ĸ ELSIF condition2 â€ĸ THEN â€ĸ {...statements to execute when condition2 is TRUE...} â€ĸ ELSE â€ĸ {...statements to execute when both condition1 and condition2 are FALSE ...} â€ĸ END IF;
  • 6. â€ĸ DECLARE â€ĸ a number(3) := 500; â€ĸ BEGIN â€ĸ -- check the boolean condition using if statement â€ĸ IF( a < 20 ) THEN â€ĸ -- if condition is true then print the following â€ĸ dbms_output.put_line('a is less than 20 ' ); â€ĸ ELSE â€ĸ dbms_output.put_line('a is not less than 20 ' ); â€ĸ END IF; â€ĸ dbms_output.put_line('value of a is : ' || a); â€ĸ END;
  • 7. PL/SQL Function â€ĸ The PL/SQL Function is very similar to PL/SQL Procedure. â€ĸ The main difference between procedure and a function is, a function must always return a value, and on the other hand a procedure may or may not return a value. â€ĸ Syntax to create a function: â€ĸ CREATE [OR REPLACE] FUNCTION function_name [parameters] â€ĸ [(parameter_name [IN | OUT | IN OUT] type [, ...])] â€ĸ RETURN return_datatype â€ĸ {IS | AS} â€ĸ BEGIN â€ĸ < function_body > â€ĸ END [function_name];
  • 8. â€ĸ Here: â€ĸ Function_name: specifies the name of the function. â€ĸ [OR REPLACE] option allows modifying an existing function. â€ĸ The optional parameter list contains name, mode and types of the parameters. â€ĸ IN represents that value will be passed from outside and OUT represents that this parameter will be used to return a value outside of the procedure.
  • 9. â€ĸ The function must contain a return statement. â€ĸ RETURN clause specifies that data type you are going to return from the function. â€ĸ Function_body contains the executable part. â€ĸ The AS keyword is used instead of the IS keyword for creating a standalone function.
  • 10. â€ĸ create or replace function adder(n1 in number, n2 in number) â€ĸ return number â€ĸ is â€ĸ n3 number(8); â€ĸ begin â€ĸ n3 :=n1+n2; â€ĸ return n3; â€ĸ end; â€ĸ /
  • 11. â€ĸ DECLARE â€ĸ n3 number(2); â€ĸ BEGIN â€ĸ n3 := adder(11,22); â€ĸ dbms_output.put_line('Addition is: ' || n3); â€ĸ END; â€ĸ /