SlideShare a Scribd company logo
1 of 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

More Related Content

What's hot

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 codeGeshan Manandhar
 
Modula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsModula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsJulian 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,6Duy Lâm
 
Reading Keyboard Output
Reading Keyboard OutputReading Keyboard Output
Reading Keyboard Outputshaylor_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 7Larry Nung
 

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
 
Clean code slide
Clean code slideClean code slide
Clean code slide
 
Modula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statementsModula 2 tutorial - 005 - statements
Modula 2 tutorial - 005 - statements
 
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
 
Reading Keyboard Output
Reading Keyboard OutputReading Keyboard Output
Reading Keyboard Output
 
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
 
Clean code
Clean codeClean code
Clean code
 

Viewers also liked

Journey into the New Frontier II
Journey into the New Frontier IIJourney into the New Frontier II
Journey into the New Frontier IICynthia Calongne
 
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDADRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDAfranciscarloperida
 
Global Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating DisordersGlobal Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating DisordersGlobal 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
 

Viewers also liked (6)

Sparking an Energetic Revolution
Sparking an Energetic RevolutionSparking an Energetic Revolution
Sparking an Energetic Revolution
 
Journey into the New Frontier II
Journey into the New Frontier IIJourney into the New Frontier II
Journey into the New Frontier II
 
Croston plumbing UK
Croston plumbing UKCroston plumbing UK
Croston plumbing UK
 
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDADRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
DRAMATIZED EXPERIENCE BY FRANCIS CARLO PERIDA
 
Global Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating DisordersGlobal Medical Cures™ | Eating Disorders
Global Medical Cures™ | Eating Disorders
 
Guide to Pinterest New Business Accounts
Guide to Pinterest New Business Accounts Guide to Pinterest New Business Accounts
Guide to Pinterest New Business Accounts
 

Similar to Oracle: Control Structures

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

More from oracle content

More from oracle content (13)

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

Recently uploaded

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfLoriGlavin3
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningLars Bell
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebUiPathCommunity
 
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
 
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
 
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
 
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
 
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
 
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
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024BookNet Canada
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024BookNet Canada
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.Curtis Poe
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersRaghuram Pandurangan
 
"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
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxLoriGlavin3
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupFlorian Wilhelm
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteDianaGray10
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxLoriGlavin3
 

Recently uploaded (20)

Moving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdfMoving Beyond Passwords: FIDO Paris Seminar.pdf
Moving Beyond Passwords: FIDO Paris Seminar.pdf
 
DSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine TuningDSPy a system for AI to Write Prompts and Do Fine Tuning
DSPy a system for AI to Write Prompts and Do Fine Tuning
 
Dev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio WebDev Dives: Streamline document processing with UiPath Studio Web
Dev Dives: Streamline document processing with UiPath Studio Web
 
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
 
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
 
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
 
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
 
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
 
From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .From Family Reminiscence to Scholarly Archive .
From Family Reminiscence to Scholarly Archive .
 
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
New from BookNet Canada for 2024: BNC CataList - Tech Forum 2024
 
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
Transcript: New from BookNet Canada for 2024: Loan Stars - Tech Forum 2024
 
How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.How AI, OpenAI, and ChatGPT impact business and software.
How AI, OpenAI, and ChatGPT impact business and software.
 
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
 
Generative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information DevelopersGenerative AI for Technical Writer or Information Developers
Generative AI for Technical Writer or Information Developers
 
"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
 
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
 
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptxMerck Moving Beyond Passwords: FIDO Paris Seminar.pptx
Merck Moving Beyond Passwords: FIDO Paris Seminar.pptx
 
Streamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project SetupStreamlining Python Development: A Guide to a Modern Project Setup
Streamlining Python Development: A Guide to a Modern Project Setup
 
Take control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test SuiteTake control of your SAP testing with UiPath Test Suite
Take control of your SAP testing with UiPath Test Suite
 
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptxUse of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
Use of FIDO in the Payments and Identity Landscape: FIDO Paris Seminar.pptx
 

Oracle: Control Structures

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