SlashJ
SlashJ

Reputation: 807

PL/SQL split string, get last value?

how could one split a string in PL/SQL to get the last value if the pattern look like this? :

'1;2', in this case the value i want would be 2.

Note: the splitter is the character ';' and values are of different length like '1;2 or 123;45678 etc...'

Thanks in advance!

Upvotes: 4

Views: 23614

Answers (4)

Egor Skriptunoff
Egor Skriptunoff

Reputation: 23737

regexp_substr(your_string, '[^;]*$')

Upvotes: 8

T.S.
T.S.

Reputation: 19340

In your case, you can use instr with -1 start position and Substr.

pos := instr( searchIn, ';', -1, 1)
res := substr(searchIn, pos + 1)

This should work, and if not... this is has to do it

Upvotes: 0

Justin Cave
Justin Cave

Reputation: 231661

SELECT SUBSTR( column_name, 
               INSTR( column_name, ';', -1 ) + 1 )
  FROM table_name

should work. Here is a SQL Fiddle example.

Upvotes: 13

Noel
Noel

Reputation: 10525

You should first find the position of ; using,

instr(string,';',1,1)

Then use SUBSTR function to extract the value starting from one more than the value found in previous function.

select substr(string,instr(string,';',1,1) + 1) from table;

Upvotes: 4

Related Questions