Friday, January 25, 2008

What is "ESCAPE" that I use Like condition?

I want to query "m_family%" with like condition.

SQL> select login from users where login like 'm_family%';
LOGIN
--------------------------------------------------
mnfamily
mofamily
myfamily2
myfamily3
m_family
myfamily1
myfamily5
myfamily8
myfamily4
9 rows selected.
------------------------------
Oh No, I didn't like that. so I read about like condition, I wrong Because:


The pattern can contain special pattern-matching characters:

  • An underscore (_) in the pattern matches exactly one character (as opposed to one byte in a multibyte character set) in the value.

  • A percent sign (%) in the pattern can match zero or more characters (as opposed to bytes in a multibyte character set) in the value. The pattern '%' cannot match a null.

You can include the actual characters % or _ in the pattern by using the ESCAPE clause.

So I modified my query:

SQL> select login from users where login like 'm\_family%' ESCAPE '\';
LOGIN
--------------------------------------------------
m_family
--------------------------------------------------

Wow! that's great, It make me exciting. I should read more document.

1 comment:

Is it sync'd yet? said...

Add "ALO" to you music collection if you like Jack Johnson. Also check out Donovan Frankenreiter.

Anyone that likes F5 load balancers and Jack Johnson should like those 2 bands.


Cheers,

Scott.
.