Return Oracle PL/SQL string range

Asked

Viewed 680 times

1

Good morning ! I need to return the value inside a string between a range of | in the select below I can get the value from the first |. The expected result is: 83,1

SELECT SUBSTR('1410,00|83,1|39,29|1410m|', 
       INSTR('1410,00|83,1|39,29|1410m|', '|') + 1, 
       LENGTH('1410,00|83,1|39,29|1410m|')) TTR
  FROM DUAL;

1 answer

1


You can use a regular Expression combined with the function REGEXP_SUBSTR:

select regexp_substr('1410,00|83,1|39,29|1410m|','[^\|]+',1,2) from dual

The function will apply to regular Expression [^\|]+ which will fetch a pipe (the "+" at the end means "one or more occurrences"), from position 1, returning the second occurrence.
See that as you want the second value "83.2", the final parameter of the function was "2", in case "3" will return "39.29" and so on.

Here the fiddle running: http://sqlfiddle.com/#! 4/9a6382/10

  • Ricardo Monstroo :) ! Thanks man ! I had managed to do with several SUBSTR and INSTR, but your solution got much better, thanks again !

Browser other questions tagged

You are not signed in. Login or sign up in order to post.