Oracle sql 写正则表达式

create table t(a varchar2(10));

insert into t values('北京ABc');
insert into t values('abc北京');

select regexp_substr(a,'[a-zA-Z]+') "英文",
       regexp_substr(a,'[^a-zA-Z]+') "汉字"
from t;

SYS@PROD>select regexp_substr(a,'[a-zA-Z]+') "英文", regexp_substr(a,'[^a-zA-Z]+') "汉字" from t;

英文                 汉字
-------------------- --------------------
abc                  北京
ABc                  北京


SQL> WITH strings AS (
  2    SELECT 'abc123' s FROM dual
  3    union all
  4    SELECT '123abc' s FROM dual
  5    union all
  6    SELECT 'a1b2c3' s FROM dual
  7  )
  8  select strings.s,regexp_replace(s,'[0-9]','') num_1,regexp_replace(s,'\d','') num_2 from strings;

S      NUM_1                                                                            NUM_2
------ ---------------------------------- ------------------------------------------------------------------------
abc123 abc                                                                              abc
123abc abc                                                                              abc
a1b2c3 abc                                                                              abc



SQL> select regexp_count('ABC123', '[A-Z]') test1,
  2         regexp_count('A1B2C3', '[A-Z]') test2
  3  from   dual;

     TEST1      TEST2
---------- ----------
         3          3



with t as 
        (select 'aaa,ccc,dddfff' strings from dual)
   select regexp_replace(t.strings,',',chr(10)) from t;

REGEXP_REPLACE
--------------
aaa
ccc
dddfff


SQL> select substr(sys_connect_by_path(ename,'-->'),4) "path" from emp
  2  where mgr is null
  3      connect by empno=prior mgr;

path
--------------------------------------------------------------------------------
SMITH-->FORD-->JONES-->KING
ALLEN-->BLAKE-->KING
WARD-->BLAKE-->KING
JONES-->KING
MARTIN-->BLAKE-->KING
BLAKE-->KING
CLARK-->KING
KING
TURNER-->BLAKE-->KING
JAMES-->BLAKE-->KING
FORD-->JONES-->KING
MILLER-->CLARK-->KING

12 rows selected

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值