Thursday, February 28, 2008

How to find characters in string?

Again, one of application testing people came to me and ask "How could we find character in string?". Well i suddenly remember there is one new SQL function in Oracle 10g. Lets take a look the example

vd@bahamut> select postal from t2;

POSTAL
----------
11470
11520
15880
13963
11788
11880
15576
1190a
1A7I1
11ao2
16502
15570
16890
I99it


We have 4 rows that contains character in postal code column. How do we find this 4 rows?

vd@bahamut> select postal from t2 WHERE REGEXP_LIKE (postal, '[a-zA-Z]');

POSTAL
----------
1190a
1A7I1
11ao2
I99it


yes, the answer is SQL new function REGEXP_LIKE.

[a-zA-Z] is to find from 'a' to 'z' and 'A' to 'Z'.

remember that this only work in Oracle 10g and future release


Hope this article will help you


Cheers

FZheng

2 comments:

Unknown said...

WUAHHH JADI RAJIN GINI NIH BIKIN BLOG2AN GAYA BANGETTTTT!!! HEHE
SAKING DI BNI GAK ADA KERJAAN GITU BENGONG2 HUHUHUHUHU.
YAH ANYWAY ISINYA BAGUS MAN, BISA BUAT SHARING2. TERUS DI UPDATE YEE !!! :)

sap support packs said...

This is one of the easiest query that I have used and executed several times. But you have explained the whole query very nicely in the above article. A fresher can also easily learn after examining the shared example.