从 PLSQL 中的 3 字长字符串中选择第一个和最后一个字

Selecting the first and the last word from a 3 word long string in PLSQL

例如我有这样的名字:

John Lucas Smith    
Kevin Thomas Bacon

我需要用 regexp_substr 来完成,或者替换或类似的东西。

而我想要得到的是:

John Smith    
Kevin Bacon

谢谢!

是这样的吗?

SQL> with test (col) as
  2    (select 'John Lucas Smith'   from dual union
  3     select 'Kevin Thomas Bacon' from dual union
  4     select 'Little Foot'        from dual
  5    )
  6  select regexp_substr(col, '^\w+') ||' '||
  7         regexp_substr(col, '\w+$') first_and_last
  8  from test;

FIRST_AND_LAST
-------------------------------------
John Smith
Kevin Bacon
Little Foot

SQL>