3-1. Choosing When to Execute Code

Problem

You code contains a condition, and you are interested in executing code to perform specific actions if the condition evaluates to TRUE, FALSE, or NULL.

Solution

Use an IF-THEN statement to evaluate an expression (or condition) and determine which code to execute as a result.

The following example depicts a very simple IF-THEN statement that evaluates one variable to see whether it contains a larger value than another variable. If so, then the statements contained within the IF-THEN statement are executed; otherwise, they are ignored.

DECLARE   value_one   NUMBER := &value_one;   value_two   NUMBER := &value_two; BEGIN   IF value_one > value_two THEN     DBMS_OUTPUT.PUT_LINE('value_one is greater than ...

Get Oracle and PL/SQL Recipes: A Problem-Solution Approach now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.