This preview shows pages 1–3. Sign up to view the full content.
This preview has intentionally blurred sections. Sign up to view the full version.View Full Document
Unformatted text preview: Conditional statements Learning objective After completing this topic, you should be able to implement a suitable conditional control statement in PL/SQL for a given scenario. 1. Types of control statements Conditional control enables you to control the execution of statements in a block of PL/SQL code. You can determine which statements are executed by stipulating a condition that must be satisfied. You use conditional control in almost every piece of code you write. You can direct the control of execution through your program using IF and CASE statements. IF statements enable you to perform actions selectively, based on specified conditions. There are three distinctive IF logic structures: IF THEN END IF; IF THEN ELSE END IF; IF THEN ELSIF ELSE END IF; IF THEN END IF; The IF THEN END IF; statement is the simplest form of an IF statement. The condition stipulated between IF and THEN determines whether the statements between THEN and END IF are executed. If the condition returns TRUE , the code is executed. If the condition returns FALSE , no action is taken. IF THEN ELSE END IF; The IF THEN ELSE END IF; statement implements an either/or logic and will result in the execution of one of two executable statements. Based on the condition between the IF and THEN statements, either the section of code between THEN and ELSE , or ELSE and END IF is executed. IF THEN ELSIF ELSE END IF; The IF THEN ELSIF ELSE END IF; statement is the most complex form of an IF statement. This statement should be used when you want to execute one of a number of statements. You can use this statement to handle multiple conditions within a single IF statement. Only one condition can evaluate to TRUE . You can use an IF THEN statement to test a particular condition. For example, you might want to see how many people in your company are over a certain age, or perhaps you want to find out how many people earn more than $50,000 per year. An IF THEN statement is ideal for testing such conditions. Question Identify the types of conditional control statements used in PL/SQL. Options: 1. IF THEN ELSE END IF; 2. IF THEN ELSE IF ELSE END IF; 3. IF THEN ELSIF ELSE END IF; 4. IF THEN END IF; Answer The IF THEN END IF , IF THEN ELSE END IF , and IF THEN ELSIF ELSE END IF statements are all types of conditional control statements used in PL/SQL. Option 1 is correct. This implements an either/or logic and will result in the execution of one of two executable statements. The condition between IF and THEN determines whether the statement between THEN and ELSE or the statement between ELSE and END IF is executed. Option 2 is incorrect. The use of ELSEIF , rather than ELSIF , is a common syntax error. If you use ELSE IF rather than ELSIF , the statement will fail....
View Full Document
- Spring '09
- Yelena - TA