例如“红色/绿色/蓝色” 分为以下
function counts = countn(A,n) if (A == 0) counts= 0; end if (n == mod(A,10)) disp(A); disp(floor(A/10)); disp(mod(A,10)); B = floor(A/10); counts = countn(B,n) + 1; else B = floor(A/10); countn(B,n); end end
red
red/green
red/green/blue
答案 0 :(得分:2)
您可以将substr
和inst
组合用作:
with t as
(
select 'red/green/blue' as str from dual
)
select substr(str,1,instr(str,'/',1,1)-1) str1,
substr(str,1,instr(str,'/',1,2)-1) str2,
str as str_whole
from t;
STR1 STR2 STR_WHOLE
---- ---------- --------------
red red/green red/green/blue
如果您想逐行使用,则可以通过添加具有以下样式的regexp_count
来使用:
with t as
(
select 'red/green/blue' as str from dual
)
select decode(sign(instr(str,'/',1,level)),1,substr(str,1,instr(str,'/',1,level)-1),str)
as str
from t
connect by level <= regexp_count(str,'/') + 1;
STR
--------------
red
red/green
red/green/blue