Reputation: 95
I want to split the following name as Surname and Forename in Oracle. Please note that a full name can have 2, 3, 4 or more words. Last name is the surname. So basically I want the first word from the right as Surname and the remaining string on the left is the Forename.
Examples:
Upvotes: 1
Views: 72
Reputation: 1271131
Although you can do this with regexp_substr()
, it is probably simpler with the basic string functions:
select substr(name, 1, length(name) - instr(reverse(name), ' ')) as firstname,
substr(name, length(name) - instr(reverse(name), ' ') + 1) as lastname
Upvotes: 1