正規表示式 說明及範例
--------------------------------------
[0-9] 含數字之字串
[a-z0-9] 含數字或小寫字母之字串
[a-zA-Z0-9] 含數字或字母之字串
[^] 不含括號內的字串
/^xy/ 以 “xy” 開始的字串,例如 “xyz”, “xyab”(若要比對 ^,請使用 \^)
/xy$/ 以 “xy” 結尾的字串,例如 “axy”, “abxy”以 “xy” 結尾的字串,例如 “axy”, “abxy” (若要比對 $,請使用 \$)
create
table
test_table(col1 varchar2(10), col2 varchar2(20));
insert
into
test_table
select
'1',
'測試' from
dual;
insert
into
test_table
select
'2',
'123'
from
dual;
insert
into
test_table
select
'3',
'abc'
from
dual;
insert
into
test_table
select
'4',
'abc123'
from
dual;
DECLARE
li_result number;
BEGIN
select count(*)
into
li_result
from
test_table
-- where REGEXP_LIKE(col2, '[一-鶿]' ) and col1 = '1';
where REGEXP_LIKE(col2,
'[^a-zA-Z0-9]'
)
and
col1 = '1';
dbms_output.put_line('result1:'
||
li_result);
select count(*)
into
li_result
from
test_table
where REGEXP_LIKE(col2,
'[0-9]'
)
and
col1 = '2';
dbms_output.put_line('result2:'
||
li_result);
select count(*)
into
li_result
from
test_table
where REGEXP_LIKE(col2,
'[a-zA-Z]'
)
and
col1 = '2';
dbms_output.put_line('result3:'
||
li_result);
select count(*)
into
li_result
from
test_table
where REGEXP_LIKE(col2,
'[a-zA-Z0-9]'
)
and
col1 = '2';
dbms_output.put_line('result4:'
||
li_result);
END;
--
查詢有中文的資料
SELECT column1, column2, column3, column4, column5
FROM
TABLE1
WHERE
REGEXP_LIKE(column1, '[一-鶿]');
http://tomkuo139.blogspot.tw/2014/02/oracle-plsql.html