How to remove part of the string in oracle

前端 未结 3 1713
猫巷女王i
猫巷女王i 2021-01-04 21:51

Input data:

abcdef_fhj_viji.dvc

Expected output:

fhj_viji.dvc

The part to be trimmed is not constant.

相关标签:
3条回答
  • 2021-01-04 22:05

    Use the REPLACE method

    Select REPLACE('abcdef_fhj_viji.dvc','abcde','')
    

    If you want this query for your table :

    Select REPLACE(column,'abcde','') from myTable
    

    For update :

    UPDATE TABLE
       SET column = REPLACE(column,'abcde','') 
    
    0 讨论(0)
  • 2021-01-04 22:16

    Since you didn't give a lot of information I'm gonna assume some.

    Let's assume you want a prefix of some string to be deleted. A good way to do that is by using Regular Expressions. There's a function called regexp_replace, that can find a substring of a string, depending on a pattern, and replace it with a different string. In PL/SQL you could write yourself a function using regexp_replace, like this:

    function deletePrefix(stringName in varchar2) return varchar2 is
    begin
      return regexp_replace(stringName, '^[a-zA-Z]+_', '');
    end;
    

    or just use this in plain sql like:

    regexp_replace(stringName, '^[a-zA-Z]+_', '');
    

    stringName being the string you want to process, and the ^[a-zA-Z]+_ part depending on what characters the prefix includes. Here I only included upper- and lowercase letters.

    0 讨论(0)
  • 2021-01-04 22:22
    select substr('abcdef_fhj_viji.dvc',instr('abcdef_fhj_viji.dvc','_')+1) from dual
    

    So, Its all depends on INSTR function, define from which position and which occurrence, you will get the index and pass that index to SUBSTR to get your string.

    0 讨论(0)
提交回复
热议问题