Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to remove part of the string in oracle

Tags:

sql

oracle

Input data:

abcdef_fhj_viji.dvc

Expected output:

fhj_viji.dvc

The part to be trimmed is not constant.

like image 816
user2967715 Avatar asked Nov 08 '13 05:11

user2967715


2 Answers

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','') 
like image 114
Sashi Kant Avatar answered Sep 25 '22 01:09

Sashi Kant


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.

like image 23
Ravi Avatar answered Sep 22 '22 01:09

Ravi