我有15个字符的字符串,需要循环拉动字母'a‘出现的位置。我打算使用游标在字符串中循环,但不确定如何保存每个位置的出现。
发布于 2016-09-12 22:31:53
像这样将字符串拆分成每个字符,然后根据所需的值进行过滤?
-- data setup to create a single value to test
WITH dat as (select 'ABCDEACDFA' val from DUAL)
--
SELECT lvl, strchr
from (
-- query to break the string into individual characters, returning a row for each
SELECT level lvl, substr(dat.val,level,1) strchr
FROM dat
CONNECT BY level <= length(val)
) WHERE strchr = 'A';
returns:
LVL STRCHR
1 A
6 A
10 A发布于 2016-09-12 23:28:23
下面是一个不同的方法,使用了一个较少的select和一个正则表达式。不过,我不相信它会对你的性能问题有所帮助。请试一试,让我们知道:
SQL> with tbl(str) as (
select 'Aabjggaklkjha' from dual
)
select level as position
from tbl
where upper(REGEXP_SUBSTR(str, '.', 1, level)) = 'A'
connect by level <= length(str);
POSITION
----------
1
2
7
13
SQL>https://stackoverflow.com/questions/39452533
复制相似问题