ORACLE有函数可以去掉字段里面的重复字符吗
1个回答
展开全部
没有,可以自己写SQL,或者自定义函数:
--自定义函数:
SQL> create or replace function f(pstr in varchar2) return varchar2 is
2 v_newstr varchar2(100) := null;
3 i pls_integer := 1;
4 begin
5 for i in 1 .. length(pstr) loop
6 if instr(v_newstr, substr(pstr, i, 1)) <= 0 or v_newstr is null then
7 v_newstr := v_newstr || substr(pstr, i, 1);
8 end if;
9 end loop;
10 return v_newstr;
11 end;
12 /
Function created
SQL> with tmp(col) as
2 (select 'aaaabbbcccdefg' from dual union all select 'adbdfre' from dual)
3 select col, f(col) from tmp
4 /
COL F(COL)
-------------- --------------------------------------------------------------------------------
aaaabbbcccdefg abcdefg
adbdfre adbfre
--SQL
SQL>
SQL> with tmp(col) as
2 (select 'aaaabbbcccdefg' from dual union all select 'adbdfre' from dual)
3 select col, listagg(c) within group(order by sqrt_id) as col1
4 from (select col, c, max(sqrt_id) as sqrt_id
5 from (select t.col,
6 substr(t.col, column_value, 1) as c,
7 column_value as sqrt_id
8 from tmp t,
9 table(cast(multiset
10 (select level
11 from dual
12 connect by level <= length(t.col)) as
13 sys.odcinumberlist)))
14 group by col, c)
15 group by col
16 /
COL COL1
-------------- --------------------------------------------------------------------------------
aaaabbbcccdefg abcdefg
adbdfre abdfre
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询