依葫芦画瓢git
假若有一张表正则表达式
是 部门 子ID 父ID oracle
一级部门 1 ide
二级部门 2 1函数
三级部门 3 2spa
四级部门 4 3code
个人想法是将部门表转成以下类型regexp
一级部门ID 二级部门ID 三级部门ID 四级部门ID orm
select s.deptname,
s.deptcode,
s.pk_deptdoc,
sys_connect_by_path(s.pk_deptdoc, '/') aa,
level,
sys_connect_by_path(s.deptcode, '/') bb,
-- case when s.deptcode like '99%' then
-- rtrim(regexp_substr(sys_connect_by_path(s.pk_deptdoc,'/')||'/','.*?'||'/',1,1),'/')
-- as hahaha1,
rtrim(regexp_substr(sys_connect_by_path(s.pk_deptdoc,'/')||'/','.*?'||'/',1,2),'/')
as hahaha1,
rtrim(regexp_substr(sys_connect_by_path(s.pk_deptdoc,'/')||'/','.*?'||'/',1,3),'/')
as hahaha2,
rtrim(regexp_substr(sys_connect_by_path(s.pk_deptdoc,'/')||'/','.*?'||'/',1,4),'/')
as hahaha3,
rtrim(regexp_substr(sys_connect_by_path(s.pk_deptdoc,'/')||'/','.*?'||'/',1,5),'/')
as hahaha4
-- end
from rlzy.tcl_dept s
where s.deptcode like '99%'
and (level not in (1,2,3))
start with s.pk_fathedept = ' '
connect by prior s.pk_deptdoc = s.pk_fathedept
order siblings by s.deptcodeci
-------
转个正则表达式的文章,之后详细研究下
Oracle 终于在10g中加入了对正则表达式的支持,下面就来了解一下吧!
字符 |
功能 |
^ |
标记行的开始 |
$ |
标记行的结束 |
= = |
匹配字符族,如:[=a=] 可匹配字符a、â、ã、ä、å等 |
. |
匹配任何字符(除了NULL) |
[:alnum:] |
匹配任何字母和数字 |
[:alpha:] |
匹配任何字母 |
[:blank:] |
匹配空格 |
[:cntrl:] |
匹配任何控制字符(在ASCII码表中不可打印的字符,如ESC键) |
[:digit:] |
任何数字 |
[:graph:] |
任何 标点符号、大小写字母以及数字 |
[:lower:] |
任何小写字母 |
[:print:] |
任何可打印的字符 |
[:punct:] |
任何标点符号,如,.+-=等 |
[:space:] |
任何空白字符,如回车、换行、制表等 |
[:upper:] |
任何大写字母 |
[:xdigit:] |
任何十六进制数字,即0-9A-F |
| |
分隔符 |
() |
子表达式,可做为量词或向后引用的前段 |
[char] |
匹配括号中的任何字符,[^char]表示除开括号中字符后的任何字符 |
字符 |
功能 |
* |
匹配0次或屡次 |
? |
匹配0次或1次 |
+ |
匹配1次或屡次 |
{m} |
匹配m次 |
{m,} |
匹配至少m次 |
{m,n} |
匹配至少m次,最多n次 |
\n |
引用第n个匹配 |
字符 |
功能 |
c |
匹配时区分大小写 |
i |
匹配时不区分大小写 |
m |
源字符串为多行匹配 |
n |
.可匹配任何换行符 |
SELECT REGEXP_INSTR('500 Oracle Pkwy, Redwood Shores, CA', '[o][[:alpha:]]{3}', 1, 2, 1, 'i') RESULT FROM dual; --返回32
SELECT regexp_replace('George McGovern', '([[:lower:]])([[:upper:]])', '\1 \2') city
FROM dual;