Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Difference Between IN and OR

SQL_UsersAug 19 2018 — edited Aug 21 2018

Hello,

What is the difference between the following two SQL statements,

SELECT COUNT (*)

  FROM products

WHERE t2 IN ('?', 'P?', 'P??')

and

SELECT COUNT (*)

  FROM products

WHERE (t2 = '?' OR t2 = 'P?' OR t2 = 'P??')

Does the above two can be used interchangeably? or does the above two have pros and cons?

Appreciate any insight or help.

Table DDL and sample data

CREATE TABLE products

(

   t1   NUMBER,

   t2   VARCHAR2 (32)

);

SET DEFINE OFF;

Insert into PRODUCTS

   (T1, T2)

Values

   (110, '?');

Insert into PRODUCTS

   (T1, T2)

Values

   (110, 'P?');

Insert into PRODUCTS

   (T1, T2)

Values

   (110, 'P??');

Insert into PRODUCTS

   (T1, T2)

Values

   (220, '?');

Insert into PRODUCTS

   (T1, T2)

Values

   (220, 'P?');

Insert into PRODUCTS

   (T1, T2)

Values

   (220, 'P??');

COMMIT;

Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Sep 18 2018
Added on Aug 19 2018
5 comments
6,332 views