iamnamja
asked on
Oracle SQL - Extract rightmost word in string
Hi, I need to extract the right-most word from a field that could have multiple spaces. Example: "Administration Main Boston" = "Boston"
Thanks.
Thanks.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
substr/instr method:
select substr('administration main boston', instr('administration main boston',' ',-1)+1) from dual;
select substr('administration main boston', instr('administration main boston',' ',-1)+1) from dual;
ASKER
Thank you both so much for the function.
One more question: what if I need to extract 2nd right most word? Just realized, I need to do this for some conditions. Is there a quick way to extract 2nd right most word?
"Administration Main Boston Office" = "Boston"
Thank you.
One more question: what if I need to extract 2nd right most word? Just realized, I need to do this for some conditions. Is there a quick way to extract 2nd right most word?
"Administration Main Boston Office" = "Boston"
Thank you.
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
another interesting variation for 2nd last word
reverse(regexp_substr(reve rse('Admin istration Main Boston Office'),'[^ ]+',1,2))
reverse(regexp_substr(reve
you should awared a split with slightwv as well for answering the original question
for example...
select regexp_substr('Administrat