字符串串联+替换

时间:2019-04-12 19:25:15

标签: sql regex oracle

我需要删除Oracle SQL中的重音符号,空格和特殊字符。 (我曾考虑过使用 pipe replace

到目前为止我的代码:

SELECT NR_CONHEC || ' - ' || RAZAO_SOCIAL_TRANSP FROM geq_gl_ctms_frete

例如:

7590 - J. T. TRANSPORTES LTDA. - ME

所需的输出:

7590-JTTRANSPORTESLTDA-ME

4 个答案:

答案 0 :(得分:2)

您可以尝试

 select regexp_replace('7590 - J. T. TRANSPORTES LTDA. - ME','[[:space:]]|\.')
        as "Result String"
   from dual;

 Result String
-------------------------
7590-JTTRANSPORTESLTDA-ME

对于您的情况,请替换为以下查询:

SELECT regexp_replace( NR_CONHEC || ' - ' || RAZAO_SOCIAL_TRANSP,'[[:space:]]|\.') 
  FROM geq_gl_ctms_frete;

,以及是否要删除更多特殊字符。以及除点号之外的其他重音符号,请在|\.之后添加任意内容,例如|\%|\&|\è...,然后从字符串中删除那些字符%&è

答案 1 :(得分:0)

怎么样?

SQL> with test (col) as
  2    (select '7590 - J. T. TRANSPORTES LTDA. - ME' from dual)
  3  select regexp_replace(col, '[^([:alpha:][:digit:]-)]') result
  4  from test;

RESULT
-------------------------
7590-JTTRANSPORTESLTDA-ME

SQL>

即将所有不是字母,数字或连字符的内容替换为 nothing

答案 2 :(得分:0)

这将起作用:

SELECT  NR_CONHEC||'-'|| reexp_replace(regexp_replace(RAZAO_SOCIAL_TRANSP 
RAZAO_SOCIAL_TRANSP,'.',''),' ','') FROM geq_gl_ctms_frete;

答案 3 :(得分:0)

尝试:

select regexp_replace (NR_CONHEC|| ' - ' || RAZAO_SOCIAL_TRANSP, '[^-0-9a-zA-Z]') as rez  from geq_gl_ctms_frete ;