Logical Condition
Logical Condition
The select statement is used to create different types of reports where the
Logical
user can apply the basic select, restrict the rows returned by the query,
Condition
use single row or multiple row functions and sort the data either
ascending or descending.
Explanation:
_____________________________________________________________________________________
2
MODULE OF INSTRUCTION
As shown in the output only those authors who have a type of CSIT
and book that contains the last letter equal to A are selected.
Explanation:
As shown in the output only those authors who have a type of CSIT
or either a book that contains the last letter equal to A are selected.
Explanation:
As shown in the output only those authors who have a YR_PUB not
equal to the value inside the IN (SET) are selected.
Rules of Precedence
The rules of precedence determine the order in which expressions are
evaluated and calculated.
The table in the slide lists the default order of precedence.
To override the default order of expression to be calculated first put
parentheses around the expression.
Operator Meaning
1 Arithmetic operators
2 Concatenation operator
3 Comparison conditions
4 IS [NOT] NULL, LIKE, [NOT] IN
5 [NOT] BETWEEN
6 Not equal to
7 NOT logical condition
8 AND logical condition
9 OR logical condition
Example:
SELECT (FNAME||','||LNAME)AS NAME, BOOK,
_____________________________________________________________________________________
4
MODULE OF INSTRUCTION
TYPE,AC_NO
FROM AUTHORS
WHERE TYPE='CSIT'
OR AC_NO LIKE'%S'
AND LNAME LIKE 'S%';
Output:
Explanation:
In this example, there are two conditions:
The first condition is that the AC_NO end with capital letter S and
the LNAM start with capital letter S.
The second condition is that the TYPE is CSIT.
Therefore, the SELECT statement reads as follows:
“Select the row if an author AC_NO ends with letter S and the
LNAME starts with letter S or the TYPE is equal to CSIT.
Example: with parentheses
SELECT (FNAME||','||LNAME)AS NAME, BOOK,
TYPE,AC_NO
FROM AUTHORS
WHERE (TYPE='CSIT'
OR AC_NO LIKE'%S')
AND LNAME LIKE 'S%';
Output:
Explanation:
In this example, there are two conditions:
The first condition is that the AC_NO ends with letter S or the TYPE
are equal to CSIT
The second condition is that the LNAME ends with letter S.
“Select the row if an author AC_NO ends with letter S and the
LNAME starts with letter S and the TYPE is equal to CSIT.
Lesson Summary:
In this lesson, you should have learned how to use the following
statements:
Apply the logical condition.
Identify the order of precedence.
Terms to Remember!
AND - Both component condition can be true for any record to be
selected.
Logical condition - combines the result of two component conditions
to produce a single result based on those conditions or it inverts the
result of a single condition
NOT - Reverse the value from TRUE to FALSE or FALSE to TRUE.
OR - Either component condition can be true for any record to be
selected.
Rules of precedence - determine the order in which expressions are
evaluated and calculated.
Textbook:
Oracle Press (2010). Applied Oracle Security
_____________________________________________________________________________________
6
MODULE OF INSTRUCTION
References:
Supplementary Video
https://www.youtube.com/watch?v=JRmpM9UNY-w
https://www.youtube.com/watch?v=OjJUPYS6o1E
https://www.youtube.com/watch?v=eXGOYouMkJA
Suggested Reading
SQL Tutorial. In ws3schools, Retrieved from
http://www.w3schools.com/sql/default.asp
Database management system. In Encyclopedia Britannica, Retrieved
from http://www.britannica.com/EBchecked/topic/152201/database-
management-system-DBMS.
SQL. In Encyclopedia Britannica, Retrieved from
http://www.britannica.com/EBchecked/topic/569684/SQL
Database Administration. In Encyclopedia.com, Retrieved from
http://www.encyclopedia.com/topic/Database_administration.aspx
SQL. In Encyclopedia.com, Retrieved from
http://www.encyclopedia.com/topic/SQL.aspx
Tutorialspoint.com
oracle.com
apex.oracle.com
_____________________________________________________________________________________
8