SlideShare une entreprise Scribd logo
1  sur  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

Contenu connexe

Tendances (20)

SQL JOINS
SQL JOINSSQL JOINS
SQL JOINS
 
Oracle Database Trigger
Oracle Database TriggerOracle Database Trigger
Oracle Database Trigger
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
4. plsql
4. plsql4. plsql
4. plsql
 
Database Triggers
Database TriggersDatabase Triggers
Database Triggers
 
Triggers in SQL | Edureka
Triggers in SQL | EdurekaTriggers in SQL | Edureka
Triggers in SQL | Edureka
 
Oracle
OracleOracle
Oracle
 
plsql.ppt
plsql.pptplsql.ppt
plsql.ppt
 
04 Handling Exceptions
04 Handling Exceptions04 Handling Exceptions
04 Handling Exceptions
 
Different Kinds of Exception in DBMS
Different Kinds of Exception in DBMSDifferent Kinds of Exception in DBMS
Different Kinds of Exception in DBMS
 
SQL for interview
SQL for interviewSQL for interview
SQL for interview
 
PL/SQL TRIGGERS
PL/SQL TRIGGERSPL/SQL TRIGGERS
PL/SQL TRIGGERS
 
Oracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step GuideOracle PLSQL Step By Step Guide
Oracle PLSQL Step By Step Guide
 
Trigger
TriggerTrigger
Trigger
 
Loops c++
Loops c++Loops c++
Loops c++
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
Procedure and Functions in pl/sql
Procedure and Functions in pl/sqlProcedure and Functions in pl/sql
Procedure and Functions in pl/sql
 
Aggregate functions
Aggregate functionsAggregate functions
Aggregate functions
 
Java IO
Java IOJava IO
Java IO
 
Macro-processor
Macro-processorMacro-processor
Macro-processor
 

En vedette

En vedette (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
 

Similaire à Using ORACLE Loops and Control Structures

Similaire à Using ORACLE Loops and 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
 
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
 
PLSQL Tutorial
PLSQL TutorialPLSQL Tutorial
PLSQL Tutorial
 

Plus de 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
 

Plus de 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
 

Dernier

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...Wes McKinney
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Strongerpanagenda
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Mark Goldstein
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Kaya Weers
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsRavi Sanghani
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxfnnc6jmgwh
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersNicole Novielli
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityIES VE
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity PlanDatabarracks
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationKnoldus Inc.
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Farhan Tariq
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxLoriGlavin3
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxLoriGlavin3
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfIngrid Airi González
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkPixlogix Infotech
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxLoriGlavin3
 

Dernier (20)

How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
The Future Roadmap for the Composable Data Stack - Wes McKinney - Data Counci...
 
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better StrongerModern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
Modern Roaming for Notes and Nomad – Cheaper Faster Better Stronger
 
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
Arizona Broadband Policy Past, Present, and Future Presentation 3/25/24
 
Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)Design pattern talk by Kaya Weers - 2024 (v2)
Design pattern talk by Kaya Weers - 2024 (v2)
 
Potential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and InsightsPotential of AI (Generative AI) in Business: Learnings and Insights
Potential of AI (Generative AI) in Business: Learnings and Insights
 
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptxGenerative AI - Gitex v1Generative AI - Gitex v1.pptx
Generative AI - Gitex v1Generative AI - Gitex v1.pptx
 
A Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software DevelopersA Journey Into the Emotions of Software Developers
A Journey Into the Emotions of Software Developers
 
Decarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a realityDecarbonising Buildings: Making a net-zero built environment a reality
Decarbonising Buildings: Making a net-zero built environment a reality
 
How to write a Business Continuity Plan
How to write a Business Continuity PlanHow to write a Business Continuity Plan
How to write a Business Continuity Plan
 
Data governance with Unity Catalog Presentation
Data governance with Unity Catalog PresentationData governance with Unity Catalog Presentation
Data governance with Unity Catalog Presentation
 
Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...Genislab builds better products and faster go-to-market with Lean project man...
Genislab builds better products and faster go-to-market with Lean project man...
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptxPasskey Providers and Enabling Portability: FIDO Paris Seminar.pptx
Passkey Providers and Enabling Portability: FIDO Paris Seminar.pptx
 
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptxA Deep Dive on Passkeys: FIDO Paris Seminar.pptx
A Deep Dive on Passkeys: FIDO Paris Seminar.pptx
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
Generative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdfGenerative Artificial Intelligence: How generative AI works.pdf
Generative Artificial Intelligence: How generative AI works.pdf
 
React Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App FrameworkReact Native vs Ionic - The Best Mobile App Framework
React Native vs Ionic - The Best Mobile App Framework
 
The State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptxThe State of Passkeys with FIDO Alliance.pptx
The State of Passkeys with FIDO Alliance.pptx
 

Using ORACLE Loops and 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