Reputation: 807
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
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
Reputation: 231661
SELECT SUBSTR( column_name,
INSTR( column_name, ';', -1 ) + 1 )
FROM table_name
should work. Here is a SQL Fiddle example.
Upvotes: 13
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