SlideShare uma empresa Scribd logo
1 de 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

Mais conteúdo relacionado

Mais procurados

1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQLrehaniltifat
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORSIshaRana14
 
Classification of datastructure.ppt
Classification of datastructure.pptClassification of datastructure.ppt
Classification of datastructure.pptLakshmiSamivel
 
Database abstraction
Database abstractionDatabase abstraction
Database abstractionRituBhargava7
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbmsjain.pralabh
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMSPadamNepal1
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTUREArchie Jamwal
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptxAnkit Rai
 
pl/sql Procedure
pl/sql Procedurepl/sql Procedure
pl/sql ProcedurePooja Dixit
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms ArraysManishPrajapati78
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sortingKrish_ver2
 
Computer Oragnization Flipflops
Computer Oragnization FlipflopsComputer Oragnization Flipflops
Computer Oragnization FlipflopsVanitha Chandru
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational CalculusKunal Anand
 

Mais procurados (20)

1 - Introduction to PL/SQL
1 - Introduction to PL/SQL1 - Introduction to PL/SQL
1 - Introduction to PL/SQL
 
PL/SQL - CURSORS
PL/SQL - CURSORSPL/SQL - CURSORS
PL/SQL - CURSORS
 
Classification of datastructure.ppt
Classification of datastructure.pptClassification of datastructure.ppt
Classification of datastructure.ppt
 
Database abstraction
Database abstractionDatabase abstraction
Database abstraction
 
4. plsql
4. plsql4. plsql
4. plsql
 
Procedures/functions of rdbms
Procedures/functions of rdbmsProcedures/functions of rdbms
Procedures/functions of rdbms
 
Types Of Keys in DBMS
Types Of Keys in DBMSTypes Of Keys in DBMS
Types Of Keys in DBMS
 
STACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURESTACKS IN DATASTRUCTURE
STACKS IN DATASTRUCTURE
 
K map.
K map.K map.
K map.
 
DATABASE CONSTRAINTS
DATABASE CONSTRAINTSDATABASE CONSTRAINTS
DATABASE CONSTRAINTS
 
SQL Joins.pptx
SQL Joins.pptxSQL Joins.pptx
SQL Joins.pptx
 
pl/sql Procedure
pl/sql Procedurepl/sql Procedure
pl/sql Procedure
 
Data Structure and Algorithms Arrays
Data Structure and Algorithms ArraysData Structure and Algorithms Arrays
Data Structure and Algorithms Arrays
 
SQL(DDL & DML)
SQL(DDL & DML)SQL(DDL & DML)
SQL(DDL & DML)
 
Stacks in c++
Stacks in c++Stacks in c++
Stacks in c++
 
3.9 external sorting
3.9 external sorting3.9 external sorting
3.9 external sorting
 
Computer Oragnization Flipflops
Computer Oragnization FlipflopsComputer Oragnization Flipflops
Computer Oragnization Flipflops
 
Parsing
ParsingParsing
Parsing
 
Chapter-7 Relational Calculus
Chapter-7 Relational CalculusChapter-7 Relational Calculus
Chapter-7 Relational Calculus
 
Normalization in DBMS
Normalization in DBMSNormalization in DBMS
Normalization in DBMS
 

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

Semelhante a Using ORACLE Loops and Control Structures

Semelhante a 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
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
 
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
 

Mais 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
 

Mais 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
 

Último

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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfMounikaPolabathina
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxLoriGlavin3
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .Alan Dix
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsPixlogix Infotech
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 3652toLead Limited
 
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
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxhariprasad279825
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfAddepto
 
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
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxLoriGlavin3
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024Lonnie McRorey
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????blackmambaettijean
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxBkGupta21
 

Último (20)

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
 
What is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdfWhat is DBT - The Ultimate Data Build Tool.pdf
What is DBT - The Ultimate Data Build Tool.pdf
 
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptxDigital Identity is Under Attack: FIDO Paris Seminar.pptx
Digital Identity is Under Attack: FIDO Paris Seminar.pptx
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
The Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and ConsThe Ultimate Guide to Choosing WordPress Pros and Cons
The Ultimate Guide to Choosing WordPress Pros and Cons
 
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
 
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data PrivacyTrustArc Webinar - How to Build Consumer Trust Through Data Privacy
TrustArc Webinar - How to Build Consumer Trust Through Data Privacy
 
Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365Ensuring Technical Readiness For Copilot in Microsoft 365
Ensuring Technical Readiness For Copilot in Microsoft 365
 
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
 
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
 
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Artificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptxArtificial intelligence in cctv survelliance.pptx
Artificial intelligence in cctv survelliance.pptx
 
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
 
Gen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdfGen AI in Business - Global Trends Report 2024.pdf
Gen AI in Business - Global Trends Report 2024.pdf
 
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
 
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
 
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptxThe Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
The Role of FIDO in a Cyber Secure Netherlands: FIDO Paris Seminar.pptx
 
TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024TeamStation AI System Report LATAM IT Salaries 2024
TeamStation AI System Report LATAM IT Salaries 2024
 
What is Artificial Intelligence?????????
What is Artificial Intelligence?????????What is Artificial Intelligence?????????
What is Artificial Intelligence?????????
 
unit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.pptxunit 4 immunoblotting technique complete.pptx
unit 4 immunoblotting technique complete.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