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

itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in javaAtul Sehdev
 
Relational Algebra,Types of join
Relational Algebra,Types of joinRelational Algebra,Types of join
Relational Algebra,Types of joinraj upadhyay
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in PythonSumit Satam
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data StructureMeghaj Mallick
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statementsSaad Sheikh
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQLPooja Dixit
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESVENNILAV6
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORSIshaRana14
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra pptGirdharRatne
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loadersTech_MX
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in databaseSatya P. Joshi
 

Tendances (20)

SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
itft-Decision making and branching in java
itft-Decision making and branching in javaitft-Decision making and branching in java
itft-Decision making and branching in java
 
Lab2 ddl commands
Lab2 ddl commandsLab2 ddl commands
Lab2 ddl commands
 
trigger dbms
trigger dbmstrigger dbms
trigger dbms
 
Join
JoinJoin
Join
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
Relational Algebra,Types of join
Relational Algebra,Types of joinRelational Algebra,Types of join
Relational Algebra,Types of join
 
Relational algebra in dbms
Relational algebra in dbmsRelational algebra in dbms
Relational algebra in dbms
 
Control Structures in Python
Control Structures in PythonControl Structures in Python
Control Structures in Python
 
Polish Notation In Data Structure
Polish Notation In Data StructurePolish Notation In Data Structure
Polish Notation In Data Structure
 
Loops and conditional statements
Loops and conditional statementsLoops and conditional statements
Loops and conditional statements
 
Packages in PL/SQL
Packages in PL/SQLPackages in PL/SQL
Packages in PL/SQL
 
STRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIESSTRUCTURE OF SQL QUERIES
STRUCTURE OF SQL QUERIES
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 
Relational algebra ppt
Relational algebra pptRelational algebra ppt
Relational algebra ppt
 
Cursors
CursorsCursors
Cursors
 
Advanced sql
Advanced sqlAdvanced sql
Advanced sql
 
Introduction to loaders
Introduction to loadersIntroduction to loaders
Introduction to loaders
 
Nested queries in database
Nested queries in databaseNested queries in database
Nested queries in database
 

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

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

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLScyllaDB
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...Fwdays
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Patryk Bandurski
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsMark Billinghurst
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenHervé Boutemy
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfAlex Barbosa Coqueiro
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii SoldatenkoFwdays
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024Lorenzo Miniero
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubKalema Edgar
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationSafe Software
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticscarlostorres15106
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Commit University
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):comworks
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Manik S Magar
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfSeasiaInfotech2
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr LapshynFwdays
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsSergiu Bodiu
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationRidwan Fadjar
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brandgvaughan
 

Dernier (20)

Developer Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQLDeveloper Data Modeling Mistakes: From Postgres to NoSQL
Developer Data Modeling Mistakes: From Postgres to NoSQL
 
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks..."LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
"LLMs for Python Engineers: Advanced Data Analysis and Semantic Kernel",Oleks...
 
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptxE-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
E-Vehicle_Hacking_by_Parul Sharma_null_owasp.pptx
 
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
Integration and Automation in Practice: CI/CD in Mule Integration and Automat...
 
Human Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR SystemsHuman Factors of XR: Using Human Factors to Design XR Systems
Human Factors of XR: Using Human Factors to Design XR Systems
 
DevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache MavenDevoxxFR 2024 Reproducible Builds with Apache Maven
DevoxxFR 2024 Reproducible Builds with Apache Maven
 
Unraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdfUnraveling Multimodality with Large Language Models.pdf
Unraveling Multimodality with Large Language Models.pdf
 
"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko"Debugging python applications inside k8s environment", Andrii Soldatenko
"Debugging python applications inside k8s environment", Andrii Soldatenko
 
SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024SIP trunking in Janus @ Kamailio World 2024
SIP trunking in Janus @ Kamailio World 2024
 
Unleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding ClubUnleash Your Potential - Namagunga Girls Coding Club
Unleash Your Potential - Namagunga Girls Coding Club
 
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry InnovationBeyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
Beyond Boundaries: Leveraging No-Code Solutions for Industry Innovation
 
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmaticsKotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
Kotlin Multiplatform & Compose Multiplatform - Starter kit for pragmatics
 
Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!Nell’iperspazio con Rocket: il Framework Web di Rust!
Nell’iperspazio con Rocket: il Framework Web di Rust!
 
CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):CloudStudio User manual (basic edition):
CloudStudio User manual (basic edition):
 
Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!Anypoint Exchange: It’s Not Just a Repo!
Anypoint Exchange: It’s Not Just a Repo!
 
The Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdfThe Future of Software Development - Devin AI Innovative Approach.pdf
The Future of Software Development - Devin AI Innovative Approach.pdf
 
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
"Federated learning: out of reach no matter how close",Oleksandr Lapshyn
 
DevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platformsDevEX - reference for building teams, processes, and platforms
DevEX - reference for building teams, processes, and platforms
 
My Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 PresentationMy Hashitalk Indonesia April 2024 Presentation
My Hashitalk Indonesia April 2024 Presentation
 
WordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your BrandWordPress Websites for Engineers: Elevate Your Brand
WordPress Websites for Engineers: Elevate Your Brand
 

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