Skip to main content

Posts

Showing posts with the label conditional

Setting and using your own conditional compilation flags

This post is the fourth in my series on conditional compilation. You will find links to the entire series at the bottom. In this post, I explore how to set and use conditional compilation flags (also known as inquiry directives and referred to below as ccflags ) used in $IF statements, and control which code will be included or excluded when compilation occurs. In theory, you don't need ccflags at all. You could just create a package with static constants, like DBMS_DB_VERSION , and then reference those constants in $IF statements. That makes sense when many different compilation units (packages, procedures, triggers, functions, object types) need to be consistently controlled by the same settings. With the package approach, when you change a value for the constant, the dependent program units will be invalidated, and upon recompilation, will be compiled with the new values. If, on the other hand, you want to add conditional compilation logic to a single unit, or a handful,...

PL/SQL 101: Writing conditional logic in PL/SQL

PL/SQL offers a number of options when it comes to writing conditional logic, as in variations on "If this then that". This post reviews them, and provides examples. You can choose from the following: IF statement - IF, IF-THEN, IF-ELSE, IF-ELSIF-ELSE CASE statement - simple and searched CASE CASE expression - the expression "version" of the statement (and one of my favorite elements of PL/SQL) IF Statement It's hard to imagine a programming language without a version of IF, and PL/SQL is no exception.  The IF statement either runs or skips a sequence of one or more statements, depending on a condition. The IF statement can take one of three forms, but they all have this in common: they start with "IF" and then end with "END IF;". IF THEN The simplest IF statement: if the boolean expression evaluates to TRUE then execute the statements between THEN and END IF. Example: BEGIN IF l_hire_date < SYSDATE THEN ...