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!

Select records like X% or Y%

914790Feb 17 2012 — edited Feb 17 2012
Hi,

I am trying to maintain a list of users in my database.
-----------------------------------------------------------------
SQL> create table t1(name varchar2(10));

Table created

SQL> insert into t1 values ('Arnold');

1 row inserted

SQL> insert into t1 values ('Bob');

1 row inserted

SQL> insert into t1 values ('Cathy');

1 row inserted

SQL> insert into t1 values ('Bill');

1 row inserted

SQL> commit;

Commit complete
------------------------------------------------

Now I use the following query to identify users whose names start with 'B'

---------------------------------
SQL> select * From t1 where name like 'B%';

NAME
Bob
Bill
---------------------------------------------------------------

But, I am not sure how to identify users whose names start with 'B' or 'C'.

Although the following query will satisfy my requirement, please suggest if there is a better way to achieve this.

----------------
SQL> select * From t1 where name like 'B%'
+2 union+
+3 select * From t1 where name like 'C%'+
+4 ;+

NAME
Bill
Bob
Cathy
----------------
This post has been answered by John Spencer on Feb 17 2012
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 16 2012
Added on Feb 17 2012
5 comments
1,137 views