Oracle SQL - Select OR Operator


If you use the OR operator, only one of the conditions needs to evaluate to TRUE.

select code, category, duration 
from   courses 
where  category = 'BLD' 
or     duration = 2; 

In this example, you can see that the OR operator in SQL is inclusive.

For an OR operator, conditions are evaluated in order until a TRUE condition is found.

All subsequent conditions are ignored.

This is due to the fact that for an OR operator to be satisfied, only one condition must evaluate to TRUE.

Even if you had many OR conditions, evaluation will stop as soon as the first TRUE condition is met.


SQL>-- from w w w .jav
SQL> drop table courses;

Table dropped.

SQL> create table courses(
  2  code        VARCHAR2(6)  primary key,
  3  description VARCHAR2(30) not null,
  4  category    CHAR(3)      not null,
  5  duration    NUMBER(2)    not null) ;
SQL> insert into courses values('SQL','Introduction to SQL',         'GEN',4);
SQL> insert into courses values('JSON','Oracle for application users','GEN',1);
SQL> insert into courses values('JAVA','Java for Oracle developers',  'BLD',4);
SQL> insert into courses values('PLS','Introduction to PL/SQL',      'BLD',1);
SQL> insert into courses values('XML','XML for Oracle developers',   'BLD',2);
SQL> insert into courses values('ERM','Data modeling with ERM',      'DSG',3);
SQL> insert into courses values('PMT','Process modeling techniques', 'DSG',1);
SQL> insert into courses values('RSD','Relational system design',    'DEF',2);
SQL> insert into courses values('PRO','Prototyping',                 'DSG',5);
SQL> insert into courses values('GEN','System generation',           'DSG',4);
SQL> select code, category, duration
  2  from   courses
  3  where  category = 'BLD'
  4  or     duration = 2;

------ | --- | ---------
JAVA   | BLD |  00004.00
PLS    | BLD |  00001.00
XML    | BLD |  00002.00
RSD    | DEF |  00002.00