Avatar of srikotesh
srikotesh

asked on 

how to get the substring of a column(String splitted with _ symbol) using oracle

Hi Experts,

Table name -->Test
column name -->filename
below is the file name value always it will split with 3 underscore symbols(_)
i have get the substring 2nd  underscore value-->08112017085147
values of the file name will be dynamic.
PTXYZPT_XXX00170_08112017085147_80462

can some suggest how do i fetch the substring.
Oracle Database

Avatar of undefined
Last Comment
srikotesh
Avatar of Ryan Chong
Ryan Chong
Flag of Singapore image

try use REGEXP_SUBSTR function.

REGEXP_SUBSTR
https://www.techonthenet.com/oracle/functions/regexp_substr.php

to implement:

with cte as
(
    Select 'EE_is_great_resource' yourField from dual union all
    Select 'Bla bla..' yourField from dual union all
    Select 'PTXYZPT_XXX00170_08112017085147_80462' yourField from dual
)
Select
REGEXP_SUBSTR (yourField, '[^_]+', 2, 3)
from cte

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of johnsone
johnsone
Flag of United States of America image

Blurred text
THIS SOLUTION IS ONLY AVAILABLE TO MEMBERS.
View this solution by signing up for a free trial.
Members can start a 7-Day free trial and enjoy unlimited access to the platform.
See Pricing Options
Start Free Trial
Avatar of Mark Geerlings
Mark Geerlings
Flag of United States of America image

I agree that using a combination of SUBSTR and INSTR is the most-efficient way to solve this problem.  The third parameter for INSTR (the "2" in this example): Instr(filename, '_', 1, 2) tells Oracle which occurrence of the "_" character to use.  And the "+ 1" or "- 1" along with INSTR are to adjust those values so the SUBSTR command starts or ends where you need it to.
Avatar of srikotesh
srikotesh

ASKER

thanks
Oracle Database
Oracle Database

Oracle is an object-relational database management system. It supports a large number of languages and application development frameworks. Its primary languages are SQL, PL/SQL and Java, but it also includes support for C and C++. Oracle also has its own enterprise modules and application server software.

81K
Questions
--
Followers
--
Top Experts
Get a personalized solution from industry experts
Ask the experts
Read over 600 more reviews

TRUSTED BY

IBM logoIntel logoMicrosoft logoUbisoft logoSAP logo
Qualcomm logoCitrix Systems logoWorkday logoErnst & Young logo
High performer badgeUsers love us badge
LinkedIn logoFacebook logoX logoInstagram logoTikTok logoYouTube logo