SlideShare uma empresa Scribd logo
1 de 6
Baixar para ler offline
P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h
Visit: http://gsbprogramming.blogspot.in
P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h
Visit: http://gsbprogramming.blogspot.in
Conditional statements in PL/SQL
Basic structure of a conditional statement is:
PL/SQL provides following conditional statements:
 IF THEN
 IF THEN ELSE
 IF THEN ELSIF
 Nested IF THEN ELSE
 CASE
P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h
Visit: http://gsbprogramming.blogspot.in
 IF THEN
Syntax:
IF condition THEN
<statements>
END IF;
Condition must be that statement which results a Boolean value i.e. either true or false
For example
BEGIN
IF true THEN
dbms_output.put_line(‘Condition true’);
END IF;
END;
Will always print:
true
 IF THEN ELSE
Syntax:
IF condition THEN
<statements>
ELSE
<statements>
END IF;
Condition must be that statement which results a Boolean value i.e. either true or false
For example:
DECLARE
vA number :=10;
vB number :=8;
BEGIN
IF vA>vB THEN
dbms_output.put_line(‘vA is greater’);
ELSE
dbms_output.put_line(‘vB is greater’);
END IF;
END;
Will print:
vA is greater
P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h
Visit: http://gsbprogramming.blogspot.in
 IF THEN ELSIF
Syntax:
IF condition THEN
<statements>
ELSIF condition THEN
<statements>
ELSE - -Optional
<statements>
END IF;
Condition must be that statement which results a Boolean value i.e. either true or false
For example
DECLARE
vA number :=10;
vB number :=8;
vC number :=15;
BEGIN
IF vA>vB AND vA>vC THEN
dbms_output.put_line(‘vA is greater’);
ELSIF vB>vC THEN
dbms_output.put_line(‘vB is greater’);
ELSE
dbms_output.put_line(‘vC is greater’);
END IF;
END;
Will print:
vC is greater
 Nested IF THEN ELSE
Syntax:
IF condition THEN
IF condition THEN
<statements>
ELSE
<statements>
END IF;
ELSE
<statements>
END IF;
Condition must be that statement which results a Boolean value i.e. either true or false
P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h
Visit: http://gsbprogramming.blogspot.in
For example
DECLARE
vA number :=10;
vB number :=8;
vC number :=15;
BEGIN
IF vA>vB THEN
IF vA>vC THEN
dbms_output.put_line(‘vA is greater’);
ELSE
dbms_output.put_line(‘vC is greater’);
END IF;
ELSE
IF vB>vC THEN
dbms_output.put_line(‘vB is greater’);
ELSE
dbms_output.put_line(‘vC is greater’);
END IF;
END IF;
END;
Will print:
vC is greater
 CASE
Syntax:
CASE selector
WHEN value1 THEN <statement 1>;
WHEN value2 THEN <statement 2>;
WHEN value3 THEN <statement 3>;
…..
ELSE <default statement>
END CASE;
CASE
WHEN selector=value1 THEN <statement 1>;
WHEN selector=value2 THEN <statement 2>;
WHEN selector=value3 THEN <statement 3>;
…..
ELSE <default statement>
END CASE;
Selector is a variable
For example:
P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h
Visit: http://gsbprogramming.blogspot.in
DECLARE
vA number :=10;
BEGIN
CASE vA
WHEN 10 THEN dbms_output.put_line(‘Value of vA is 10’);
ELSE dbms_output.put_line(‘Value of vA is not 10’);
END CASE;
END;
DECLARE
vA number :=10;
BEGIN
CASE
WHEN vA=10 THEN dbms_output.put_line(‘Value of vA is 10’);
ELSE dbms_output.put_line(‘Value of vA is not 10’);
END CASE;
END;
Will print:
Value of vA is 10
Note: When there is no matching case then an error will be shown. So always write ELSE statement i.e.
default statement in CASE, although it is not mandatory but is recommended. For example, the code
below will produce an error:
DECLARE
vA number :=100;
BEGIN
CASE vA
WHEN 10 THEN dbms_output.put_line(‘Value of vA is 10’);
END CASE;
END;
ORA-06592: CASE not found while executing CASE statement

Mais conteúdo relacionado

Destaque (10)

Sistemas operativos prof.julia
Sistemas operativos prof.juliaSistemas operativos prof.julia
Sistemas operativos prof.julia
 
Reciclas
ReciclasReciclas
Reciclas
 
Presentación1
Presentación1Presentación1
Presentación1
 
Legislación de la comunicación
Legislación de la comunicaciónLegislación de la comunicación
Legislación de la comunicación
 
TEFFICK RAGBEER Resume 01
TEFFICK RAGBEER Resume 01TEFFICK RAGBEER Resume 01
TEFFICK RAGBEER Resume 01
 
Analise de conteudo
Analise de conteudoAnalise de conteudo
Analise de conteudo
 
Caminho MaríTimo Para O Brasil
Caminho MaríTimo Para O BrasilCaminho MaríTimo Para O Brasil
Caminho MaríTimo Para O Brasil
 
Hallow'een 2012 | Teacher Isabel Ferreira
Hallow'een 2012 | Teacher Isabel FerreiraHallow'een 2012 | Teacher Isabel Ferreira
Hallow'een 2012 | Teacher Isabel Ferreira
 
Easter Egg Hunt - E.B. da Estalagem
Easter Egg Hunt - E.B. da EstalagemEaster Egg Hunt - E.B. da Estalagem
Easter Egg Hunt - E.B. da Estalagem
 
Slide historia
Slide historiaSlide historia
Slide historia
 

Mais de Gurpreet singh

Mais de Gurpreet singh (20)

Introduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP ReportingIntroduction to Oracle Fusion BIP Reporting
Introduction to Oracle Fusion BIP Reporting
 
Why Messaging system?
Why Messaging system?Why Messaging system?
Why Messaging system?
 
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...Understanding Flex Fields with  Accounting Flexfields(Chart of Accounts) in O...
Understanding Flex Fields with Accounting Flexfields(Chart of Accounts) in O...
 
Oracle Application Developmenr Framework
Oracle Application Developmenr FrameworkOracle Application Developmenr Framework
Oracle Application Developmenr Framework
 
Java Servlet part 3
Java Servlet part 3Java Servlet part 3
Java Servlet part 3
 
Oracle advanced queuing
Oracle advanced queuingOracle advanced queuing
Oracle advanced queuing
 
Oracle SQL Part 3
Oracle SQL Part 3Oracle SQL Part 3
Oracle SQL Part 3
 
Oracle SQL Part 2
Oracle SQL Part 2Oracle SQL Part 2
Oracle SQL Part 2
 
Oracle SQL Part1
Oracle SQL Part1Oracle SQL Part1
Oracle SQL Part1
 
Generics and collections in Java
Generics and collections in JavaGenerics and collections in Java
Generics and collections in Java
 
IO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxingIO Streams, Serialization, de-serialization, autoboxing
IO Streams, Serialization, de-serialization, autoboxing
 
Java Servlets Part 2
Java Servlets Part 2Java Servlets Part 2
Java Servlets Part 2
 
Creating business group in oracle apps
Creating business group in oracle appsCreating business group in oracle apps
Creating business group in oracle apps
 
Defing locations in Oracle Apps
Defing locations in Oracle AppsDefing locations in Oracle Apps
Defing locations in Oracle Apps
 
Assigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYSTAssigning role AME_BUS_ANALYST
Assigning role AME_BUS_ANALYST
 
PL/SQL Part 5
PL/SQL Part 5PL/SQL Part 5
PL/SQL Part 5
 
PL/SQL Part 3
PL/SQL Part 3PL/SQL Part 3
PL/SQL Part 3
 
PL/SQL Part 2
PL/SQL Part 2PL/SQL Part 2
PL/SQL Part 2
 
Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)Introduction to Data Flow Diagram (DFD)
Introduction to Data Flow Diagram (DFD)
 
Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)Ingenium test(Exam Management System) Project Presentation (Full)
Ingenium test(Exam Management System) Project Presentation (Full)
 

Último

Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
panagenda
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Victor Rentea
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
?#DUbAI#??##{{(☎️+971_581248768%)**%*]'#abortion pills for sale in dubai@
 

Último (20)

Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin WoodPolkadot JAM Slides - Token2049 - By Dr. Gavin Wood
Polkadot JAM Slides - Token2049 - By Dr. Gavin Wood
 
Why Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire businessWhy Teams call analytics are critical to your entire business
Why Teams call analytics are critical to your entire business
 
presentation ICT roal in 21st century education
presentation ICT roal in 21st century educationpresentation ICT roal in 21st century education
presentation ICT roal in 21st century education
 
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot ModelMcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
Mcleodganj Call Girls 🥰 8617370543 Service Offer VIP Hot Model
 
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024Finding Java's Hidden Performance Traps @ DevoxxUK 2024
Finding Java's Hidden Performance Traps @ DevoxxUK 2024
 
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdfRising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
Rising Above_ Dubai Floods and the Fortitude of Dubai International Airport.pdf
 
Vector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptxVector Search -An Introduction in Oracle Database 23ai.pptx
Vector Search -An Introduction in Oracle Database 23ai.pptx
 
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
+971581248768>> SAFE AND ORIGINAL ABORTION PILLS FOR SALE IN DUBAI AND ABUDHA...
 
Corporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptxCorporate and higher education May webinar.pptx
Corporate and higher education May webinar.pptx
 
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWEREMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
EMPOWERMENT TECHNOLOGY GRADE 11 QUARTER 2 REVIEWER
 
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
Apidays New York 2024 - The Good, the Bad and the Governed by David O'Neill, ...
 
CNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In PakistanCNIC Information System with Pakdata Cf In Pakistan
CNIC Information System with Pakdata Cf In Pakistan
 
How to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected WorkerHow to Troubleshoot Apps for the Modern Connected Worker
How to Troubleshoot Apps for the Modern Connected Worker
 
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​Elevate Developer Efficiency & build GenAI Application with Amazon Q​
Elevate Developer Efficiency & build GenAI Application with Amazon Q​
 
FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024FWD Group - Insurer Innovation Award 2024
FWD Group - Insurer Innovation Award 2024
 
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data DiscoveryTrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
TrustArc Webinar - Unlock the Power of AI-Driven Data Discovery
 
Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..Understanding the FAA Part 107 License ..
Understanding the FAA Part 107 License ..
 
DBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor PresentationDBX First Quarter 2024 Investor Presentation
DBX First Quarter 2024 Investor Presentation
 
Six Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal OntologySix Myths about Ontologies: The Basics of Formal Ontology
Six Myths about Ontologies: The Basics of Formal Ontology
 
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
Biography Of Angeliki Cooney | Senior Vice President Life Sciences | Albany, ...
 

PL/SQL Part 4

  • 1. P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h Visit: http://gsbprogramming.blogspot.in
  • 2. P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h Visit: http://gsbprogramming.blogspot.in Conditional statements in PL/SQL Basic structure of a conditional statement is: PL/SQL provides following conditional statements:  IF THEN  IF THEN ELSE  IF THEN ELSIF  Nested IF THEN ELSE  CASE
  • 3. P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h Visit: http://gsbprogramming.blogspot.in  IF THEN Syntax: IF condition THEN <statements> END IF; Condition must be that statement which results a Boolean value i.e. either true or false For example BEGIN IF true THEN dbms_output.put_line(‘Condition true’); END IF; END; Will always print: true  IF THEN ELSE Syntax: IF condition THEN <statements> ELSE <statements> END IF; Condition must be that statement which results a Boolean value i.e. either true or false For example: DECLARE vA number :=10; vB number :=8; BEGIN IF vA>vB THEN dbms_output.put_line(‘vA is greater’); ELSE dbms_output.put_line(‘vB is greater’); END IF; END; Will print: vA is greater
  • 4. P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h Visit: http://gsbprogramming.blogspot.in  IF THEN ELSIF Syntax: IF condition THEN <statements> ELSIF condition THEN <statements> ELSE - -Optional <statements> END IF; Condition must be that statement which results a Boolean value i.e. either true or false For example DECLARE vA number :=10; vB number :=8; vC number :=15; BEGIN IF vA>vB AND vA>vC THEN dbms_output.put_line(‘vA is greater’); ELSIF vB>vC THEN dbms_output.put_line(‘vB is greater’); ELSE dbms_output.put_line(‘vC is greater’); END IF; END; Will print: vC is greater  Nested IF THEN ELSE Syntax: IF condition THEN IF condition THEN <statements> ELSE <statements> END IF; ELSE <statements> END IF; Condition must be that statement which results a Boolean value i.e. either true or false
  • 5. P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h Visit: http://gsbprogramming.blogspot.in For example DECLARE vA number :=10; vB number :=8; vC number :=15; BEGIN IF vA>vB THEN IF vA>vC THEN dbms_output.put_line(‘vA is greater’); ELSE dbms_output.put_line(‘vC is greater’); END IF; ELSE IF vB>vC THEN dbms_output.put_line(‘vB is greater’); ELSE dbms_output.put_line(‘vC is greater’); END IF; END IF; END; Will print: vC is greater  CASE Syntax: CASE selector WHEN value1 THEN <statement 1>; WHEN value2 THEN <statement 2>; WHEN value3 THEN <statement 3>; ….. ELSE <default statement> END CASE; CASE WHEN selector=value1 THEN <statement 1>; WHEN selector=value2 THEN <statement 2>; WHEN selector=value3 THEN <statement 3>; ….. ELSE <default statement> END CASE; Selector is a variable For example:
  • 6. P L / S Q L T u t o r i a l - B y E r G u r p r e e t S i n g h Visit: http://gsbprogramming.blogspot.in DECLARE vA number :=10; BEGIN CASE vA WHEN 10 THEN dbms_output.put_line(‘Value of vA is 10’); ELSE dbms_output.put_line(‘Value of vA is not 10’); END CASE; END; DECLARE vA number :=10; BEGIN CASE WHEN vA=10 THEN dbms_output.put_line(‘Value of vA is 10’); ELSE dbms_output.put_line(‘Value of vA is not 10’); END CASE; END; Will print: Value of vA is 10 Note: When there is no matching case then an error will be shown. So always write ELSE statement i.e. default statement in CASE, although it is not mandatory but is recommended. For example, the code below will produce an error: DECLARE vA number :=100; BEGIN CASE vA WHEN 10 THEN dbms_output.put_line(‘Value of vA is 10’); END CASE; END; ORA-06592: CASE not found while executing CASE statement