如何用正则取美国人名.


类似”Celmer,Kenneth Raymond”,"Cockrell Jr,Robert Charles”,"St John,Michael Raymond”需要取出颠倒然后用空格分隔取出第一个名字“Kenneth Celmer”,”Robert Cockrell”,”Michael St’。

通过ITPUB高手指点,可用如下代码实现。

SELECT
name full_name,
REGEXP_REPLACE(name,'\s*(\S+)[^,]*\,+\s*(\S+)[^,]*','\2 \1')
name,
userid username,
emplid,
jobtitle title,
location,
business_unit_4,
empl_status status
FROM employee_data@dwtst_tms t ,tms_location loc
WHERE loc.business_unit=t.location and jobcode IN
('000055', '000457', '000449', '000383', '000492', '000308');

另种写法:

select column_value src_name, regexp_replace(column_value, '([^ ]*)([^,]*),([^ ]*).*', '\3 \1') real_name
2 from table(sys.odcivarchar2list('DAngelo,James Thomas' ,'Perez Nunez,Ricardo','Czarnecki,Curtis A'))

原文地址:https://www.cnblogs.com/tracy/p/2081300.html