How can I find the last occurrence of a character in a string? For instance, I want to find the position of the last "s" in the following string:
abcdfshakfdbfkdsksbdw
Find the last occurrence of a char in a string
Moderator: NorbertKrupa
Find the last occurrence of a char in a string
Thank, Fred
- JimKnicely
- Site Admin
- Posts: 1825
- Joined: Sat Jan 21, 2012 4:58 am
- Contact:
Re: Find the last occurrence of a char in a string
fsalvelt,
You can use a -1 as the starting position of the INSTR function so that it works backwards.
Example
You can use a -1 as the starting position of the INSTR function so that it works backwards.
Example
Code: Select all
dbadmin=> select instr('abcdfshakfdbfkdsksbdw', 's', -1);
instr
-------
18
(1 row)
Jim Knicely
Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.
Note: I work for Vertica. My views, opinions, and thoughts expressed here do not represent those of my employer.