WITH t(str) AS
(
SELECT '99k9220000709999' FROM DUAL
), t2 AS
(
SELECT regexp_substr(str,'[^[:alpha:]]+$') as str
FROM t
)
SELECT substr( str,1, length(str)-5 ) as "Result"
FROM t2
SQL> with test (id, account) as
2 (select 1, '99k9220000709999' from dual union all
3 select 2, '002LF004828xx' from dual
4 ),
5 split as
6 (select id,
7 column_value lvl,
8 regexp_substr(account, '[^.]', 1, column_value) chr,
9 max(length(account)) over (order by null) len
10 from test cross join table(cast(multiset(select level from dual
11 connect by level <= length(account)
12 ) as sys.odcinumberlist))
13 )
14 select id,
15 listagg(chr, '') within group (order by lvl) result
16 from split
17 where lvl between 4 and len - 5
18 group by id;
ID RESULT
---------- --------------------
1 92200007
2 LF004828
SQL>
4条答案
按热度按时间8zzbczxx1#
substr
应该可以做到这一点-从位置4开始,取列的长度减去5+3=8:字符串
biswetbf2#
另一种方法是左修剪部分,直到字母结束的字符,然后提取剩下的字符串,不包括最后五个字符,
字符串
esbemjvw3#
如果我们能把它复杂化(为了好玩),为什么要把它简单化呢?
字符串
wz3gfoph4#
你可以使用
substr()
和length()
。另一种方法是使用正则表达式:字符串
但这不一定是最有效的方法。