Udjuni.com

udjuni.com search:




PL/SQL expressions and Boolean operators


Expressions are part of PL/SQL that evaluates to something, but is not valid on its own. For example, an expression can appear on the right hand side of an assignment operator, but that expression can not be used on its own, it has to e part of another statement. For example, 2 + 3 * 3 is an expression, but can not be executed as it is.

Evaluating expressions


The precedence of the operator determines the order of evaluation. For example Multiplication has a higher precedence than addition, thus the expression above as it is will be evaluates as 2 + 9 = 11. But if we needed to give the addition of 2 and 3, precedence before multiplying their result by 3; we will have to put those two in parenthesis or brackets. Thus, we will have (2 + 3) * 3 = 15.

Types of PL/SQL expressions



Boolean Expressions - these are the kinds of expressions that return either TRUE or FALSE. For example a > b, (2 < 4) OR (-2 > c), NULL are all valid Boolean expressions. The way it works is that you take one of the three Boolean operators (AND, OR, NOT), these operators take one or more arguments and return either TRUE or FALSE. Here is a small table of how Boolean operators work :


NOT |TRUE |FALSE|NULL
-------------------------
|FALSE|TRUE |NULL




This means that the not operator always return the opposite of the argument supplied, except when that argument is NULL, then the answer will still be NULL. Now let us take a look at how the AND operator works:

AND |TRUE |FALSE|NULL
-------------------------
TRUE |TRUE |FALSE |NULL
FALSE |FALSE|FALSE |FALSE
NULL |NULL |FALSE |NULL


This means, the AND operator only returns TRUE when both arguments are TRUE. It returns FALSE when one of the arguments evaluates to FALSE and then Returns null when at least one of the arguments evaluates to NULL and the other argument does not evaluate to FALSE. Here is what happens when an OR operator is applied:

OR |TRUE |FALSE|NULL
-------------------------
TRUE |TRUE |TRUE |TRUE
FALSE |TRUE |FALSE|NULL
NULL |TRUE |NULL |NULL


As you can see from the table above, with the OR Operator, you only need one argument to evaluate to TRUE for the whole expression to result in a TRUE. And a FALSE with a NULL always result in a NULL.

character expressions

The only character operator in PL/SQL is the concatenation (||). This is used to merge two strings or characters into one string. For example, 'My name' || 'is Mamamia' evaluates to 'My name is Mamamia'.

Comparison operators

This group of operators include the equality(=), inequality (!=), less than (<), less than or equal to (<=), greater than (>) and greater than or equal to (>=). For these operators, they can only return NULL if their operant is NULL.

LIKE operator is used to match patterns in character strings. It makes use of characters and symbols such as (%) to denote a match of zero or more characters. The underscore ( _ ) is used to match exactly one character. You can also take a look at SQL BETWEEN and IN operators





RELATED ARTICLES:


Evaluating Algebraic Expressions - BODMAS
When evaluating algebraic expressions, you will need to follow the right order of operations in order to get the right answer. In this posting we will cover the approach we call BODMAS - which denotes the order inwhich operators are applied: BODMAS stands for (Brackets -> Or

Expanding brackets and factorizing expressions
Expanding Brackets Expanding brackets is actually much easier than most people think. To expand brackets such as a(b + c), all you have to do is multiply the term outside the bracket by everything inside the bracket (e.g. 2x(x + 2) = 2x2 +

The SQL IN and BETWEEN operators
Say for example that, you have a list of 30 employee numbers and would like to get information on them. Instead of writing a complex and long query validating each number with operators such as Like, you could simply use the IN operator. The syntax for using the IN operator is as foll

operators


Substitution and Evaluating


Did not find it? Try udjuni.com search:







© 2009 UdjunI LLC. All rights reserved | Privacy policy | Tutorial Index | RSS Feed