1

I am trying to find a way in oracle SQL to take all the text after the 1st "/" FROM THE RIGHT to the 4th "/". I need to do this in one SQL statement..

table name: access_log
col name: download
value: Download file:/webdocs/data/groupXXX/case/03_28_54_9_0000011856.pdf

I am trying to end up with

case

then a count of how many matches? can this be done?

3
  • Given REVERSE reverses a string, maybe you can reverse, match from the left, reverse? Commented Nov 24, 2014 at 19:01
  • 1
    Actually, it has to be possible with (possibly multiple) REGEXP_SUBSTR? Commented Nov 24, 2014 at 19:04
  • Sorry, but i don't understand what you want to count exactly Commented Nov 24, 2014 at 20:21

2 Answers 2

1
select regexp_replace('Download file:/webdocs/data/groupXXX/case/03_28_54_9_0000011856.pdf', 
                      '.*/([^/]+)/[^/]*$', '\1') from dual;
Sign up to request clarification or add additional context in comments.

3 Comments

I dont need from the hard code values I need it from the database value
@JMS perhaps you could provide more sample records to test either approach provided.
I did to find the value and count how many times it is in the database
0

A Simple SUBSTR approach works from Oracle 10g+

select TRIM(BOTH '/' FROM 
          substr(
                  download,
                  INSTR(download,'/',1,4),
                  INSTR(download,'/',1,5)-INSTR(download,'/',1,4)
                 )
           )
FROM ACCESS_LOG;

And count could be,

SELECT
COUNT(
         CASE WHEN TRIM(BOTH '/' FROM 
                        substr(
                                download,
                                INSTR(download,'/',1,4),
                                INSTR(download,'/',1,5)-INSTR(download,'/',1,4)
                               )
                         ) = 'case'
         THEN
             1
         END
       ) COUNT_MATCHED
FROM 
     ACCESS_LOG;

2 Comments

i need this coming from the database not the hard coded value
huh? I dont understand

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.