SlideShare a Scribd company logo
1Using ORACLE®LOOPS and CONTROL structures
2CONTROL STRUCTURESControl structures are those constructs that alter the flow of program execution.
3LOOPSControl 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 loopFor loop.FOR counter INLwr_bnd..Upr_bndLOOPStatement 1;…………END LOOPloopStatement 1;…….…….EXIT WHEN[condition]END LOOPWHILE( condition) LOOPStatement 1……..…….END LOOP
4SIMPLE LOOPA 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;BEGINLOOP	SELECT age INTO eage FROM InfoTable WHERE 	age = counter;	DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage);		         SYNTAX	counter += 5;	EXIT WHEN counter >50;END LOOPENDloopStatement 1;…….…….EXIT WHEN[condition]END LOOP
5WHILE LOOPThe 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;BEGINWHILE counter <55	LOOP	SELECT age INTO eage FROM InfoTable WHERE 	age = counter;	DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage);		         SYNTAXcounter += 5;	END LOOPENDWHILE( condition) LOOPStatement 1……..…….END LOOP
6LOOPSThe 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:DECLAREename VARCHAR2(20);eage NUMBER := 40;BEGINFOR i IN 40..55LOOPselect name INTO ename FROM Infotable WHERE age = eage;	SYNTAXeage := eage+5;DBMS_OUTPUT.PUT_LINE('Name is'||ename);END LOOP;ENDFOR counter INLwr_bnd..Upr_bndLOOPStatement 1;…………END LOOP
7NESTED LOOPSWe can nest one loop inside another by giving labels to the loops.SYNTAX<<outer_loop>>label for outer loopLOOP      <<inner_loop>>	label for inner loopLOOP	Statement 1;      	 …..       	EXIT WHEN [cond]       	END LOOP inner _loop;Statement 1;…………EXIT WHEN [cond]END LOOP outer_loop;<<outer_loop>>FOR counter INLwr_bnd..Upr_bndLOOP      <<inner_loop>      LOOP      Statement 1;       …..       EXIT WHEN [cond]END LOOP Inner _loop;Statement 1;…………END LOOP Outer_loop;
8SELECTIVE STATEMENTSSelective statements are the constructs that perform the action based on the condition that is satisfied.There are four selective constructs:IFIF…..ELSEIF……ELSIF……ELSECASEIF (condition..)THENStatement1;Statement2;ELSIF     Statement1;     Statement2;ELSE     Statement1;     Statement2;END IF;IF (condition..)THENStatement1;Statement2;……END IF;IF (condition..)THENStatement1;Statement2;ELSEStatement1;Statement2;END IF;CASE selectorWHEN expression 1 THEN  result 1;WHEN expression 2 THEN  result 2;…….ELSE [result n]END
9IFThe 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);BEGINename :=&ename;IF ename=‘Bill‘ THENDBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome');END IF;ENDThe above code outputs “Hi BILL!Welcome” if the user enters the name as Bill else no output is shown.IF (condition..)THENStatement1;Statement2;……END IF;
10IF….ELSEThe 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);BEGINename :=&ename;IF ename='bill‘ THENDBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome');ELSEDBMS_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..)THENStatement1;Statement2;ELSEStatement1;Statement2;END IF;
11IF…ELSIF…ELSEThe 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);BEGINename :=&ename;IF ename=‘Bill‘ THENDBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome');ELSIF ename= ‘Steve’ THENDBMS_OUTPUT.PUT_LINE(‘Hi Steve! Come on in');ELSEDBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill or steve ');END IF;ENDHere 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..)THENStatement1;Statement2;ELSIF     Statement1;     Statement2;ELSE     Statement1;     Statement2;END IF;
12CASEThe 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);BEGINename :=&ename;CASE enameWHEN ‘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;ENDHere 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 selectorWHEN expression 1 THEN  result 1;WHEN expression 2 THEN  result 2;…….ELSE [result n]END
THANK YOU13THANK YOU FOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit:  www.dataminingtools.net

More Related Content

What's hot (7)

7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
Clean code slide
Clean code slideClean code slide
Clean code slide
Anh Huan Miu
 
Modula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsModula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statements
Julian Miglio
 
Refactoring group 1 - chapter 3,4,6
Refactoring   group 1 - chapter 3,4,6Refactoring   group 1 - chapter 3,4,6
Refactoring group 1 - chapter 3,4,6
Duy Lâm
 
Reading Keyboard Output
Reading Keyboard OutputReading Keyboard Output
Reading Keyboard Output
shaylor_swift
 
PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7
Larry Nung
 
Clean code
Clean codeClean code
Clean code
Henrique Smoco
 
7 rules of simple and maintainable code
7 rules of simple and maintainable code7 rules of simple and maintainable code
7 rules of simple and maintainable code
Geshan Manandhar
 
Modula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsModula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statements
Julian Miglio
 
Refactoring group 1 - chapter 3,4,6
Refactoring   group 1 - chapter 3,4,6Refactoring   group 1 - chapter 3,4,6
Refactoring group 1 - chapter 3,4,6
Duy Lâm
 
Reading Keyboard Output
Reading Keyboard OutputReading Keyboard Output
Reading Keyboard Output
shaylor_swift
 
PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7PL/SQL & SQL CODING GUIDELINES – Part 7
PL/SQL & SQL CODING GUIDELINES – Part 7
Larry Nung
 

Viewers also liked (6)

Sparking an Energetic Revolution
Sparking an Energetic RevolutionSparking an Energetic Revolution
Sparking an Energetic Revolution
Evonne (Evo) Heyning
 
Journey into the New Frontier II
Journey into the New Frontier IIJourney into the New Frontier II
Journey into the New Frontier II
Cynthia Calongne
 
Croston plumbing UK
Croston plumbing UKCroston plumbing UK
Croston plumbing UK
crostonplumbing
 
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDADRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
franciscarloperida
 
Global Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating DisordersGlobal Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating Disorders
Global Medical Cures™
 
Guide to Pinterest New Business Accounts
Guide to Pinterest New Business Accounts Guide to Pinterest New Business Accounts
Guide to Pinterest New Business Accounts
Gianluigi Spagnoli
 
Journey into the New Frontier II
Journey into the New Frontier IIJourney into the New Frontier II
Journey into the New Frontier II
Cynthia Calongne
 
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDADRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
franciscarloperida
 
Global Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating DisordersGlobal Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating Disorders
Global Medical Cures™
 
Guide to Pinterest New Business Accounts
Guide to Pinterest New Business Accounts Guide to Pinterest New Business Accounts
Guide to Pinterest New Business Accounts
Gianluigi Spagnoli
 

Similar to Oracle: Control Structures (20)

Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04Oracle - Program with PL/SQL - Lession 04
Oracle - Program with PL/SQL - Lession 04
Thuan Nguyen
 
PLSQL (1).ppt
PLSQL (1).pptPLSQL (1).ppt
PLSQL (1).ppt
MadhuriAnaparthy
 
Les19[1]Writing Control Structures
Les19[1]Writing Control StructuresLes19[1]Writing Control Structures
Les19[1]Writing Control Structures
siavosh kaviani
 
PLSQL Note
PLSQL NotePLSQL Note
PLSQL Note
Arun Sial
 
PL/SQL___________________________________
PL/SQL___________________________________PL/SQL___________________________________
PL/SQL___________________________________
NiharikaKeshari
 
Pseudocode
PseudocodePseudocode
Pseudocode
Harsha Madushanka
 
Plsql
PlsqlPlsql
Plsql
Mandeep Singh
 
ORACLE PL/SQL
ORACLE PL/SQLORACLE PL/SQL
ORACLE PL/SQL
ASHABOOPATHY
 
c++ Lecture 3
c++ Lecture 3c++ Lecture 3
c++ Lecture 3
sajidpk92
 
PL-SQL.pdf
PL-SQL.pdfPL-SQL.pdf
PL-SQL.pdf
Anas Nakash
 
Flow of control ppt
Flow of control pptFlow of control ppt
Flow of control ppt
Indraprastha Institute of Information Technology
 
Programming in Arduino (Part 2)
Programming in Arduino  (Part 2)Programming in Arduino  (Part 2)
Programming in Arduino (Part 2)
Niket Chandrawanshi
 
Pl sql chapter 2
Pl sql chapter 2Pl sql chapter 2
Pl sql chapter 2
PrabhatKumar591
 
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
Thuan Nguyen
 
Lecture Notes Unit5 chapter 15 PL/SQL Programming
Lecture Notes Unit5 chapter 15 PL/SQL ProgrammingLecture Notes Unit5 chapter 15 PL/SQL Programming
Lecture Notes Unit5 chapter 15 PL/SQL Programming
Murugan146644
 
Kotlin For Beginners - CheezyCode
Kotlin For Beginners - CheezyCodeKotlin For Beginners - CheezyCode
Kotlin For Beginners - CheezyCode
Cheezy Code
 
SQl
SQlSQl
SQl
sarankumarv
 
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
Krishna Raj
 
lecture4 control flow instruction in assembly.pptx
lecture4 control flow instruction in assembly.pptxlecture4 control flow instruction in assembly.pptx
lecture4 control flow instruction in assembly.pptx
malnaham
 
C language 2
C language 2C language 2
C language 2
Arafat Bin Reza
 
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
Thuan Nguyen
 
Les19[1]Writing Control Structures
Les19[1]Writing Control StructuresLes19[1]Writing Control Structures
Les19[1]Writing Control Structures
siavosh kaviani
 
PL/SQL___________________________________
PL/SQL___________________________________PL/SQL___________________________________
PL/SQL___________________________________
NiharikaKeshari
 
c++ Lecture 3
c++ Lecture 3c++ Lecture 3
c++ Lecture 3
sajidpk92
 
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
Thuan Nguyen
 
Lecture Notes Unit5 chapter 15 PL/SQL Programming
Lecture Notes Unit5 chapter 15 PL/SQL ProgrammingLecture Notes Unit5 chapter 15 PL/SQL Programming
Lecture Notes Unit5 chapter 15 PL/SQL Programming
Murugan146644
 
Kotlin For Beginners - CheezyCode
Kotlin For Beginners - CheezyCodeKotlin For Beginners - CheezyCode
Kotlin For Beginners - CheezyCode
Cheezy Code
 
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
Krishna Raj
 
lecture4 control flow instruction in assembly.pptx
lecture4 control flow instruction in assembly.pptxlecture4 control flow instruction in assembly.pptx
lecture4 control flow instruction in assembly.pptx
malnaham
 

More from oracle content (13)

Oracle: Procedures
Oracle: ProceduresOracle: Procedures
Oracle: Procedures
oracle content
 
Oracle: PLSQL Introduction
Oracle: PLSQL IntroductionOracle: PLSQL Introduction
Oracle: PLSQL Introduction
oracle content
 
Oracle : DML
Oracle : DMLOracle : DML
Oracle : DML
oracle content
 
Oracle: Programs
Oracle: ProgramsOracle: Programs
Oracle: Programs
oracle content
 
Oracle: Commands
Oracle: CommandsOracle: Commands
Oracle: Commands
oracle content
 
Oracle: Joins
Oracle: JoinsOracle: Joins
Oracle: Joins
oracle content
 
Oracle:Cursors
Oracle:CursorsOracle:Cursors
Oracle:Cursors
oracle content
 
Oracle: Dw Design
Oracle: Dw DesignOracle: Dw Design
Oracle: Dw Design
oracle content
 
Oracle: Basic SQL
Oracle: Basic SQLOracle: Basic SQL
Oracle: Basic SQL
oracle content
 
Oracle Warehouse
Oracle WarehouseOracle Warehouse
Oracle Warehouse
oracle content
 
Oracle: Functions
Oracle: FunctionsOracle: Functions
Oracle: Functions
oracle content
 
Oracle: New Plsql
Oracle: New PlsqlOracle: New Plsql
Oracle: New Plsql
oracle content
 
Oracle: Fundamental Of Dw
Oracle: Fundamental Of DwOracle: Fundamental Of Dw
Oracle: Fundamental Of Dw
oracle content
 

Recently uploaded (20)

TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 
TrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business ConsultingTrsLabs - Fintech Product & Business Consulting
TrsLabs - Fintech Product & Business Consulting
Trs Labs
 
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptxSpecial Meetup Edition - TDX Bengaluru Meetup #52.pptx
Special Meetup Edition - TDX Bengaluru Meetup #52.pptx
shyamraj55
 
How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?How Can I use the AI Hype in my Business Context?
How Can I use the AI Hype in my Business Context?
Daniel Lehner
 
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc Webinar: Consumer Expectations vs Corporate Realities on Data Broker...
TrustArc
 
Procurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptxProcurement Insights Cost To Value Guide.pptx
Procurement Insights Cost To Value Guide.pptx
Jon Hansen
 
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes Partner Innovation Updates for May 2025
ThousandEyes
 
Electronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploitElectronic_Mail_Attacks-1-35.pdf by xploit
Electronic_Mail_Attacks-1-35.pdf by xploit
niftliyevhuseyn
 
Role of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered ManufacturingRole of Data Annotation Services in AI-Powered Manufacturing
Role of Data Annotation Services in AI-Powered Manufacturing
Andrew Leo
 
Technology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data AnalyticsTechnology Trends in 2025: AI and Big Data Analytics
Technology Trends in 2025: AI and Big Data Analytics
InData Labs
 
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath MaestroDev Dives: Automate and orchestrate your processes with UiPath Maestro
Dev Dives: Automate and orchestrate your processes with UiPath Maestro
UiPathCommunity
 
Mobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi ArabiaMobile App Development Company in Saudi Arabia
Mobile App Development Company in Saudi Arabia
Steve Jonas
 
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep DiveDesigning Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
Designing Low-Latency Systems with Rust and ScyllaDB: An Architectural Deep Dive
ScyllaDB
 
Build Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For DevsBuild Your Own Copilot & Agents For Devs
Build Your Own Copilot & Agents For Devs
Brian McKeiver
 
2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx2025-05-Q4-2024-Investor-Presentation.pptx
2025-05-Q4-2024-Investor-Presentation.pptx
Samuele Fogagnolo
 
Generative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in BusinessGenerative Artificial Intelligence (GenAI) in Business
Generative Artificial Intelligence (GenAI) in Business
Dr. Tathagat Varma
 
Big Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur MorganBig Data Analytics Quick Research Guide by Arthur Morgan
Big Data Analytics Quick Research Guide by Arthur Morgan
Arthur Morgan
 
Drupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy ConsumptionDrupalcamp Finland – Measuring Front-end Energy Consumption
Drupalcamp Finland – Measuring Front-end Energy Consumption
Exove
 
AI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global TrendsAI and Data Privacy in 2025: Global Trends
AI and Data Privacy in 2025: Global Trends
InData Labs
 
Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.Greenhouse_Monitoring_Presentation.pptx.
Greenhouse_Monitoring_Presentation.pptx.
hpbmnnxrvb
 
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Massive Power Outage Hits Spain, Portugal, and France: Causes, Impact, and On...
Aqusag Technologies
 

Oracle: Control Structures

  • 1. 1Using ORACLE®LOOPS and CONTROL structures
  • 2. 2CONTROL STRUCTURESControl structures are those constructs that alter the flow of program execution.
  • 3. 3LOOPSControl 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 loopFor loop.FOR counter INLwr_bnd..Upr_bndLOOPStatement 1;…………END LOOPloopStatement 1;…….…….EXIT WHEN[condition]END LOOPWHILE( condition) LOOPStatement 1……..…….END LOOP
  • 4. 4SIMPLE LOOPA 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;BEGINLOOP SELECT age INTO eage FROM InfoTable WHERE age = counter; DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage); SYNTAX counter += 5; EXIT WHEN counter >50;END LOOPENDloopStatement 1;…….…….EXIT WHEN[condition]END LOOP
  • 5. 5WHILE LOOPThe 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;BEGINWHILE counter <55 LOOP SELECT age INTO eage FROM InfoTable WHERE age = counter; DBMS_OUTPUT.PUT_LINE(‘Age is’ ||eage); SYNTAXcounter += 5; END LOOPENDWHILE( condition) LOOPStatement 1……..…….END LOOP
  • 6. 6LOOPSThe 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:DECLAREename VARCHAR2(20);eage NUMBER := 40;BEGINFOR i IN 40..55LOOPselect name INTO ename FROM Infotable WHERE age = eage; SYNTAXeage := eage+5;DBMS_OUTPUT.PUT_LINE('Name is'||ename);END LOOP;ENDFOR counter INLwr_bnd..Upr_bndLOOPStatement 1;…………END LOOP
  • 7. 7NESTED LOOPSWe can nest one loop inside another by giving labels to the loops.SYNTAX<<outer_loop>>label for outer loopLOOP <<inner_loop>> label for inner loopLOOP Statement 1; ….. EXIT WHEN [cond] END LOOP inner _loop;Statement 1;…………EXIT WHEN [cond]END LOOP outer_loop;<<outer_loop>>FOR counter INLwr_bnd..Upr_bndLOOP <<inner_loop> LOOP Statement 1; ….. EXIT WHEN [cond]END LOOP Inner _loop;Statement 1;…………END LOOP Outer_loop;
  • 8. 8SELECTIVE STATEMENTSSelective statements are the constructs that perform the action based on the condition that is satisfied.There are four selective constructs:IFIF…..ELSEIF……ELSIF……ELSECASEIF (condition..)THENStatement1;Statement2;ELSIF Statement1; Statement2;ELSE Statement1; Statement2;END IF;IF (condition..)THENStatement1;Statement2;……END IF;IF (condition..)THENStatement1;Statement2;ELSEStatement1;Statement2;END IF;CASE selectorWHEN expression 1 THEN result 1;WHEN expression 2 THEN result 2;…….ELSE [result n]END
  • 9. 9IFThe 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);BEGINename :=&ename;IF ename=‘Bill‘ THENDBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome');END IF;ENDThe above code outputs “Hi BILL!Welcome” if the user enters the name as Bill else no output is shown.IF (condition..)THENStatement1;Statement2;……END IF;
  • 10. 10IF….ELSEThe 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);BEGINename :=&ename;IF ename='bill‘ THENDBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome');ELSEDBMS_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..)THENStatement1;Statement2;ELSEStatement1;Statement2;END IF;
  • 11. 11IF…ELSIF…ELSEThe 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);BEGINename :=&ename;IF ename=‘Bill‘ THENDBMS_OUTPUT.PUT_LINE('Hi BILL!Welcome');ELSIF ename= ‘Steve’ THENDBMS_OUTPUT.PUT_LINE(‘Hi Steve! Come on in');ELSEDBMS_OUTPUT.PUT_LINE(‘ Sorry!Access only to bill or steve ');END IF;ENDHere 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..)THENStatement1;Statement2;ELSIF Statement1; Statement2;ELSE Statement1; Statement2;END IF;
  • 12. 12CASEThe 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);BEGINename :=&ename;CASE enameWHEN ‘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;ENDHere 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 selectorWHEN expression 1 THEN result 1;WHEN expression 2 THEN result 2;…….ELSE [result n]END
  • 13. THANK YOU13THANK YOU FOR VIEWING THIS PRESENTATIONFOR MORE PRESENTATIONS AND VIDEOS ON ORACLE AND DATAMINING ,please visit: www.dataminingtools.net