SlideShare ist ein Scribd-Unternehmen logo
1 von 13
1 Using ORACLE® LOOPS and CONTROL structures
2 CONTROL STRUCTURES Control structures are those constructs that alter the flow of program execution.
3 LOOPS Control structures are those constructs that alter the flow of program execution. Loop is one such control structure. A loop iterates a given set of statements until a condition is satisfied. There are three types of looping constructs: Simple loop. While loop For loop. FOR counter IN Lwr_bnd..Upr_bnd LOOP Statement 1; …… …… END LOOP loop Statement 1; ……. ……. EXIT WHEN[condition] END LOOP WHILE( condition) LOOP Statement 1 …….. ……. END LOOP
4 SIMPLE LOOP A simple loop begins with a LOOP keyword, ends with a END LOOP keyword and in between are the statements to be performed. We must include an EXIT WHEN statement to set the exit condition or else it will form an infinite loop. EXAMPLE: DECLARE	ename VARCHAR2(20);    	counter NUMBER :=40; BEGIN LOOP 	SELECT age INTO eage FROM InfoTable WHERE  	age = counter; 	DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage);		         SYNTAX 	counter += 5; 	EXIT WHEN counter >50; END LOOP END loop Statement 1; ……. ……. EXIT WHEN[condition] END LOOP
5 WHILE LOOP The WHILE loop is an entry control loop meaning that the condition is checked while entering the loop unlike the Simple loop where condition is checked while exit. EXAMPLE: DECLARE	ename VARCHAR2(20);    	counter NUMBER :=40; BEGIN WHILE counter <55	 LOOP 	SELECT age INTO eage FROM InfoTable WHERE  	age = counter; 	DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage);		         SYNTAX counter += 5;	 END LOOP END WHILE( condition) LOOP Statement 1 …….. ……. END LOOP
6 LOOPS The FOR loop is an entry control loop with a LOWER_BOUND.. UPPER_BOUND specified in the condition in the same format. The counter variable will be implicitly declared. EXAMPLE: DECLARE ename VARCHAR2(20); eage NUMBER := 40; BEGIN FOR i IN 40..55 LOOP select name INTO ename FROM Infotable WHERE age = eage;	SYNTAX eage := eage+5; DBMS_OUTPUT.PUT_LINE('Name is'||ename); END LOOP; END FOR counter IN Lwr_bnd..Upr_bnd LOOP Statement 1; …… …… END LOOP
7 NESTED LOOPS We can nest one loop inside another by giving labels to the loops. SYNTAX <<outer_loop>>label for outer loop LOOP       <<inner_loop>>	label for inner loop LOOP	Statement 1;       	 …..        	EXIT WHEN [cond]        	END LOOP inner _loop; Statement 1; …… …… EXIT WHEN [cond] END LOOP outer_loop; <<outer_loop>> FOR counter IN Lwr_bnd..Upr_bnd LOOP       <<inner_loop>       LOOP       Statement 1;        …..        EXIT WHEN [cond] END LOOP Inner _loop; Statement 1; …… …… END LOOP Outer_loop;
8 SELECTIVE STATEMENTS Selective statements are the constructs that perform the action based on the condition that is satisfied.There are four selective constructs: IF IF…..ELSE IF……ELSIF……ELSE CASE IF (condition..) THEN Statement1; Statement2; ELSIF      Statement1;      Statement2; ELSE      Statement1;      Statement2; END IF; IF (condition..) THEN Statement1; Statement2; …… END IF; IF (condition..) THEN Statement1; Statement2; ELSE Statement1; Statement2; END IF; CASE selector WHEN expression 1 THEN  result 1; WHEN expression 2 THEN  result 2; ……. ELSE [result n] END
9 IF The IF statement has a condition ,which when satisfied the statements in its body are executed else the are not executed. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; IF ename=‘Bill‘ THEN DBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome'); END IF; END The above code outputs “Hi BILL!Welcome” if the user enters the name as Bill else no output is shown. IF (condition..) THEN Statement1; Statement2; …… END IF;
10 IF….ELSE The IF statement provides only the action to be taken if condition is satisfied . But the IF…ELSE construct provides both the actions to be taken when the condition is satisfied given in the IF block and the action when it is not which is given in the ELSE block. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; IF ename='bill‘ THEN DBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome'); ELSE DBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill '); END IF; END 		Here the output is 'Hi BILL! Welcome’ when user enters Bill and displays 		the message “Sorry! Access only to bill “ if the user enters any other 			name. IF (condition..) THEN Statement1; Statement2; ELSE Statement1; Statement2; END IF;
11 IF…ELSIF…ELSE The IF statement provides only the action to be taken if condition is satisfied . But the IF…ELSEIF…ELSE construct provides both the actions to be taken when one the condition ,another action if another condition is satisfies and finally the action is both conditions fail. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; IF ename=‘Bill‘ THEN DBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome'); ELSIF ename= ‘Steve’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Steve! Come on in'); ELSE DBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill or steve '); END IF; END Here the output is 'Hi BILL! Welcome’ when user enters Bill, output is 'Hi Steve! Come on in’ 		when user enters Steve and displays the message "Sorry! Access only to bill “ if the user 		enters any other name. IF (condition..) THEN Statement1; Statement2; ELSIF      Statement1;      Statement2; ELSE      Statement1;      Statement2; END IF;
12 CASE The CASE construct is a special form of the ELSIF construct which matches a selector values with list of expresions and if either is matched the executes those statements. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; CASE ename WHEN ‘Bill’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Bill! Come on in'); WHEN ‘Steve’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Steve! Come on in'); WHEN ‘Larry’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Larry! Come on in’); ELSE  DBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill or steve or larry '); END IF; END Here the output is 'Hi BILL! Come on in’ when user enters Bill, output is 'Hi Steve! Come on 		in’ when user enters Steve and output is 'Hi Larry! Come on in’ when user enters Larry and 		displays the message "Sorry! Access only to bill “ if the user enters any other name. CASE selector WHEN expression 1 THEN  result 1; WHEN expression 2 THEN  result 2; ……. ELSE [result n] END
THANK YOU 13 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit:   www.dataminingtools.net

Weitere ähnliche Inhalte

Was ist angesagt? (20)

SQL Functions
SQL FunctionsSQL Functions
SQL Functions
 
SQL Commands
SQL Commands SQL Commands
SQL Commands
 
Relational Algebra,Types of join
Relational Algebra,Types of joinRelational Algebra,Types of join
Relational Algebra,Types of join
 
Cursors
CursorsCursors
Cursors
 
Sql joins
Sql joinsSql joins
Sql joins
 
Triggers
TriggersTriggers
Triggers
 
Sql commands
Sql commandsSql commands
Sql commands
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
Using the set operators
Using the set operatorsUsing the set operators
Using the set operators
 
Sql Tutorials
Sql TutorialsSql Tutorials
Sql Tutorials
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptions
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
05 Creating Stored Procedures
05 Creating Stored Procedures05 Creating Stored Procedures
05 Creating Stored Procedures
 
Joins And Its Types
Joins And Its TypesJoins And Its Types
Joins And Its Types
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
Sql commands
Sql commandsSql commands
Sql commands
 
Introduction to triggers
Introduction to triggersIntroduction to triggers
Introduction to triggers
 

Andere mochten auch

Andere mochten auch (20)

SPSS: File Managment
SPSS: File ManagmentSPSS: File Managment
SPSS: File Managment
 
MySql:Introduction
MySql:IntroductionMySql:Introduction
MySql:Introduction
 
Jive Clearspace Best#2598 C8
Jive  Clearspace  Best#2598 C8Jive  Clearspace  Best#2598 C8
Jive Clearspace Best#2598 C8
 
System Init
System InitSystem Init
System Init
 
Knowledge Discovery
Knowledge DiscoveryKnowledge Discovery
Knowledge Discovery
 
LISP:Loops In Lisp
LISP:Loops In LispLISP:Loops In Lisp
LISP:Loops In Lisp
 
Data Applied: Association
Data Applied: AssociationData Applied: Association
Data Applied: Association
 
R: Apply Functions
R: Apply FunctionsR: Apply Functions
R: Apply Functions
 
WEKA: Output Knowledge Representation
WEKA: Output Knowledge RepresentationWEKA: Output Knowledge Representation
WEKA: Output Knowledge Representation
 
LíRica Latina 2ºBac Lara Lozano
LíRica Latina 2ºBac Lara LozanoLíRica Latina 2ºBac Lara Lozano
LíRica Latina 2ºBac Lara Lozano
 
Ccc
CccCcc
Ccc
 
Clickthrough
ClickthroughClickthrough
Clickthrough
 
Festivals Refuerzo
Festivals RefuerzoFestivals Refuerzo
Festivals Refuerzo
 
Huidige status van de testtaal TTCN-3
Huidige status van de testtaal TTCN-3Huidige status van de testtaal TTCN-3
Huidige status van de testtaal TTCN-3
 
Data Mining The Sky
Data Mining The SkyData Mining The Sky
Data Mining The Sky
 
XL-MINER:Prediction
XL-MINER:PredictionXL-MINER:Prediction
XL-MINER:Prediction
 
Ontwikkeling In Eigen Handen Nl Web
Ontwikkeling In Eigen Handen Nl WebOntwikkeling In Eigen Handen Nl Web
Ontwikkeling In Eigen Handen Nl Web
 
MS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rulesMS SQL SERVER: Microsoft sequence clustering and association rules
MS SQL SERVER: Microsoft sequence clustering and association rules
 
Probability And Its Axioms
Probability And Its AxiomsProbability And Its Axioms
Probability And Its Axioms
 
Procedures And Functions in Matlab
Procedures And Functions in MatlabProcedures And Functions in Matlab
Procedures And Functions in Matlab
 

Ähnlich wie Oracle: Control Structures

Ähnlich wie Oracle: Control Structures (20)

Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04
 
PLSQL (1).ppt
PLSQL (1).pptPLSQL (1).ppt
PLSQL (1).ppt
 
Les19[1]Writing Control Structures
Les19[1]Writing Control StructuresLes19[1]Writing Control Structures
Les19[1]Writing Control Structures
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
 
Pseudocode
PseudocodePseudocode
Pseudocode
 
Plsql
PlsqlPlsql
Plsql
 
c++ Lecture 3
c++ Lecture 3c++ Lecture 3
c++ Lecture 3
 
PL-SQL.pdf
PL-SQL.pdfPL-SQL.pdf
PL-SQL.pdf
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
 
Pl sql chapter 2
Pl sql chapter 2Pl sql chapter 2
Pl sql chapter 2
 
Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06Oracle - Program with PL/SQL - Lession 06
Oracle - Program with PL/SQL - Lession 06
 
Kotlin For Beginners - CheezyCode
Kotlin For Beginners - CheezyCodeKotlin For Beginners - CheezyCode
Kotlin For Beginners - CheezyCode
 
SQl
SQlSQl
SQl
 
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KRLoops IN COMPUTER SCIENCE STANDARD 11 BY KR
Loops IN COMPUTER SCIENCE STANDARD 11 BY KR
 
C language 2
C language 2C language 2
C language 2
 
Loops c++
Loops c++Loops c++
Loops c++
 
Loop structures
Loop structuresLoop structures
Loop structures
 
loops in C ppt.pdf
loops in C ppt.pdfloops in C ppt.pdf
loops in C ppt.pdf
 
L9 l10 server side programming
L9 l10  server side programmingL9 l10  server side programming
L9 l10 server side programming
 

Mehr von DataminingTools Inc

AI: Introduction to artificial intelligence
AI: Introduction to artificial intelligenceAI: Introduction to artificial intelligence
AI: Introduction to artificial intelligenceDataminingTools Inc
 
Data Mining: Text and web mining
Data Mining: Text and web miningData Mining: Text and web mining
Data Mining: Text and web miningDataminingTools Inc
 
Data Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataData Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataDataminingTools Inc
 
Data Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlationsData Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlationsDataminingTools Inc
 
Data Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysisData Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysisDataminingTools Inc
 
Data warehouse and olap technology
Data warehouse and olap technologyData warehouse and olap technology
Data warehouse and olap technologyDataminingTools Inc
 

Mehr von DataminingTools Inc (20)

Terminology Machine Learning
Terminology Machine LearningTerminology Machine Learning
Terminology Machine Learning
 
Techniques Machine Learning
Techniques Machine LearningTechniques Machine Learning
Techniques Machine Learning
 
Machine learning Introduction
Machine learning IntroductionMachine learning Introduction
Machine learning Introduction
 
Areas of machine leanring
Areas of machine leanringAreas of machine leanring
Areas of machine leanring
 
AI: Planning and AI
AI: Planning and AIAI: Planning and AI
AI: Planning and AI
 
AI: Logic in AI 2
AI: Logic in AI 2AI: Logic in AI 2
AI: Logic in AI 2
 
AI: Logic in AI
AI: Logic in AIAI: Logic in AI
AI: Logic in AI
 
AI: Learning in AI 2
AI: Learning in AI 2AI: Learning in AI 2
AI: Learning in AI 2
 
AI: Learning in AI
AI: Learning in AI AI: Learning in AI
AI: Learning in AI
 
AI: Introduction to artificial intelligence
AI: Introduction to artificial intelligenceAI: Introduction to artificial intelligence
AI: Introduction to artificial intelligence
 
AI: Belief Networks
AI: Belief NetworksAI: Belief Networks
AI: Belief Networks
 
AI: AI & Searching
AI: AI & SearchingAI: AI & Searching
AI: AI & Searching
 
AI: AI & Problem Solving
AI: AI & Problem SolvingAI: AI & Problem Solving
AI: AI & Problem Solving
 
Data Mining: Text and web mining
Data Mining: Text and web miningData Mining: Text and web mining
Data Mining: Text and web mining
 
Data Mining: Outlier analysis
Data Mining: Outlier analysisData Mining: Outlier analysis
Data Mining: Outlier analysis
 
Data Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence dataData Mining: Mining stream time series and sequence data
Data Mining: Mining stream time series and sequence data
 
Data Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlationsData Mining: Mining ,associations, and correlations
Data Mining: Mining ,associations, and correlations
 
Data Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysisData Mining: Graph mining and social network analysis
Data Mining: Graph mining and social network analysis
 
Data warehouse and olap technology
Data warehouse and olap technologyData warehouse and olap technology
Data warehouse and olap technology
 
Data Mining: Data processing
Data Mining: Data processingData Mining: Data processing
Data Mining: Data processing
 

Kürzlich hochgeladen

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoffsammart93
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...DianaGray10
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024The Digital Insurer
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...Martijn de Jong
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsMaria Levchenko
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUK Journal
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024The Digital Insurer
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...apidays
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processorsdebabhi2
 
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 WorkerThousandEyes
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherRemote DBA Services
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...apidays
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptxHampshireHUG
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘RTylerCroy
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonAnna Loughnan Colquhoun
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesBoston Institute of Analytics
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Miguel Araújo
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024Rafal Los
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Scriptwesley chun
 

Kürzlich hochgeladen (20)

TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law DevelopmentsTrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
TrustArc Webinar - Stay Ahead of US State Data Privacy Law Developments
 
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot TakeoffStrategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
Strategize a Smooth Tenant-to-tenant Migration and Copilot Takeoff
 
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
Connector Corner: Accelerate revenue generation using UiPath API-centric busi...
 
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
Bajaj Allianz Life Insurance Company - Insurer Innovation Award 2024
 
2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...2024: Domino Containers - The Next Step. News from the Domino Container commu...
2024: Domino Containers - The Next Step. News from the Domino Container commu...
 
Handwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed textsHandwritten Text Recognition for manuscripts and early printed texts
Handwritten Text Recognition for manuscripts and early printed texts
 
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdfUnderstanding Discord NSFW Servers A Guide for Responsible Users.pdf
Understanding Discord NSFW Servers A Guide for Responsible Users.pdf
 
Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024Partners Life - Insurer Innovation Award 2024
Partners Life - Insurer Innovation Award 2024
 
Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...Apidays New York 2024 - The value of a flexible API Management solution for O...
Apidays New York 2024 - The value of a flexible API Management solution for O...
 
Exploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone ProcessorsExploring the Future Potential of AI-Enabled Smartphone Processors
Exploring the Future Potential of AI-Enabled Smartphone Processors
 
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
 
Strategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a FresherStrategies for Landing an Oracle DBA Job as a Fresher
Strategies for Landing an Oracle DBA Job as a Fresher
 
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
Apidays Singapore 2024 - Building Digital Trust in a Digital Economy by Veron...
 
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
04-2024-HHUG-Sales-and-Marketing-Alignment.pptx
 
🐬 The future of MySQL is Postgres 🐘
🐬  The future of MySQL is Postgres   🐘🐬  The future of MySQL is Postgres   🐘
🐬 The future of MySQL is Postgres 🐘
 
Data Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt RobisonData Cloud, More than a CDP by Matt Robison
Data Cloud, More than a CDP by Matt Robison
 
HTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation StrategiesHTML Injection Attacks: Impact and Mitigation Strategies
HTML Injection Attacks: Impact and Mitigation Strategies
 
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
Mastering MySQL Database Architecture: Deep Dive into MySQL Shell and MySQL R...
 
The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024The 7 Things I Know About Cyber Security After 25 Years | April 2024
The 7 Things I Know About Cyber Security After 25 Years | April 2024
 
Automating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps ScriptAutomating Google Workspace (GWS) & more with Apps Script
Automating Google Workspace (GWS) & more with Apps Script
 

Oracle: Control Structures

  • 1. 1 Using ORACLE® LOOPS and CONTROL structures
  • 2. 2 CONTROL STRUCTURES Control structures are those constructs that alter the flow of program execution.
  • 3. 3 LOOPS Control structures are those constructs that alter the flow of program execution. Loop is one such control structure. A loop iterates a given set of statements until a condition is satisfied. There are three types of looping constructs: Simple loop. While loop For loop. FOR counter IN Lwr_bnd..Upr_bnd LOOP Statement 1; …… …… END LOOP loop Statement 1; ……. ……. EXIT WHEN[condition] END LOOP WHILE( condition) LOOP Statement 1 …….. ……. END LOOP
  • 4. 4 SIMPLE LOOP A simple loop begins with a LOOP keyword, ends with a END LOOP keyword and in between are the statements to be performed. We must include an EXIT WHEN statement to set the exit condition or else it will form an infinite loop. EXAMPLE: DECLARE ename VARCHAR2(20); counter NUMBER :=40; BEGIN LOOP SELECT age INTO eage FROM InfoTable WHERE age = counter; DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage); SYNTAX counter += 5; EXIT WHEN counter >50; END LOOP END loop Statement 1; ……. ……. EXIT WHEN[condition] END LOOP
  • 5. 5 WHILE LOOP The WHILE loop is an entry control loop meaning that the condition is checked while entering the loop unlike the Simple loop where condition is checked while exit. EXAMPLE: DECLARE ename VARCHAR2(20); counter NUMBER :=40; BEGIN WHILE counter <55 LOOP SELECT age INTO eage FROM InfoTable WHERE age = counter; DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage); SYNTAX counter += 5; END LOOP END WHILE( condition) LOOP Statement 1 …….. ……. END LOOP
  • 6. 6 LOOPS The FOR loop is an entry control loop with a LOWER_BOUND.. UPPER_BOUND specified in the condition in the same format. The counter variable will be implicitly declared. EXAMPLE: DECLARE ename VARCHAR2(20); eage NUMBER := 40; BEGIN FOR i IN 40..55 LOOP select name INTO ename FROM Infotable WHERE age = eage; SYNTAX eage := eage+5; DBMS_OUTPUT.PUT_LINE('Name is'||ename); END LOOP; END FOR counter IN Lwr_bnd..Upr_bnd LOOP Statement 1; …… …… END LOOP
  • 7. 7 NESTED LOOPS We can nest one loop inside another by giving labels to the loops. SYNTAX <<outer_loop>>label for outer loop LOOP <<inner_loop>> label for inner loop LOOP Statement 1; ….. EXIT WHEN [cond] END LOOP inner _loop; Statement 1; …… …… EXIT WHEN [cond] END LOOP outer_loop; <<outer_loop>> FOR counter IN Lwr_bnd..Upr_bnd LOOP <<inner_loop> LOOP Statement 1; ….. EXIT WHEN [cond] END LOOP Inner _loop; Statement 1; …… …… END LOOP Outer_loop;
  • 8. 8 SELECTIVE STATEMENTS Selective statements are the constructs that perform the action based on the condition that is satisfied.There are four selective constructs: IF IF…..ELSE IF……ELSIF……ELSE CASE IF (condition..) THEN Statement1; Statement2; ELSIF Statement1; Statement2; ELSE Statement1; Statement2; END IF; IF (condition..) THEN Statement1; Statement2; …… END IF; IF (condition..) THEN Statement1; Statement2; ELSE Statement1; Statement2; END IF; CASE selector WHEN expression 1 THEN result 1; WHEN expression 2 THEN result 2; ……. ELSE [result n] END
  • 9. 9 IF The IF statement has a condition ,which when satisfied the statements in its body are executed else the are not executed. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; IF ename=‘Bill‘ THEN DBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome'); END IF; END The above code outputs “Hi BILL!Welcome” if the user enters the name as Bill else no output is shown. IF (condition..) THEN Statement1; Statement2; …… END IF;
  • 10. 10 IF….ELSE The IF statement provides only the action to be taken if condition is satisfied . But the IF…ELSE construct provides both the actions to be taken when the condition is satisfied given in the IF block and the action when it is not which is given in the ELSE block. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; IF ename='bill‘ THEN DBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome'); ELSE DBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill '); END IF; END Here the output is 'Hi BILL! Welcome’ when user enters Bill and displays the message “Sorry! Access only to bill “ if the user enters any other name. IF (condition..) THEN Statement1; Statement2; ELSE Statement1; Statement2; END IF;
  • 11. 11 IF…ELSIF…ELSE The IF statement provides only the action to be taken if condition is satisfied . But the IF…ELSEIF…ELSE construct provides both the actions to be taken when one the condition ,another action if another condition is satisfies and finally the action is both conditions fail. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; IF ename=‘Bill‘ THEN DBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome'); ELSIF ename= ‘Steve’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Steve! Come on in'); ELSE DBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill or steve '); END IF; END Here the output is 'Hi BILL! Welcome’ when user enters Bill, output is 'Hi Steve! Come on in’ when user enters Steve and displays the message "Sorry! Access only to bill “ if the user enters any other name. IF (condition..) THEN Statement1; Statement2; ELSIF Statement1; Statement2; ELSE Statement1; Statement2; END IF;
  • 12. 12 CASE The CASE construct is a special form of the ELSIF construct which matches a selector values with list of expresions and if either is matched the executes those statements. EXAMPLE: VARIABLE ename VARCHAR2(20); BEGIN ename :=&ename; CASE ename WHEN ‘Bill’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Bill! Come on in'); WHEN ‘Steve’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Steve! Come on in'); WHEN ‘Larry’ THEN DBMS_OUTPUT.PUT_LINE(‘Hi Larry! Come on in’); ELSE DBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill or steve or larry '); END IF; END Here the output is 'Hi BILL! Come on in’ when user enters Bill, output is 'Hi Steve! Come on in’ when user enters Steve and output is 'Hi Larry! Come on in’ when user enters Larry and displays the message "Sorry! Access only to bill “ if the user enters any other name. CASE selector WHEN expression 1 THEN result 1; WHEN expression 2 THEN result 2; ……. ELSE [result n] END
  • 13. THANK YOU 13 THANK YOU FOR VIEWING THIS PRESENTATION FOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING , please visit: www.dataminingtools.net