Lets say when I run the following query,
SELECT NAME 开发者_如何学运维
FROM EMP;
It return the following 2 rows.
NAME
------------
Jan Jones
Arne Barnie
But I wanted it in the following format
J. Jones
A. Barnie
How I can get that?
It should be possible with regexp_replace
:
with names as (
select 'Jan Jones' name from dual union all
select 'Arne Barnie' name from dual
)
select
regexp_replace(name, '(.)[[:alpha:]]* *([[:alpha:]]*)', '\1. \2') name
from
names;
Alternatively, if you prefer the \X
notation over the [[:...:]]
notation, you can use
regexp_replace(name, '(.)\w* *(\w*)', '\1. \2')
There are no short cuts like DECODE
to do this
I think this is your best bet.
精彩评论