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

String 从PLSQL中的3字长字符串中选择第一个字和最后一个字,string,plsql,substr,String,Plsql,Substr,例如,我有这样的名字: John Lucas Smith Kevin Thomas Bacon 我需要用regexp\u substr或者replace之类的东西来完成它 我想得到的是: John Smith Kevin Bacon 谢谢大家! 像这样的 SQL> with test (col) as 2 (select 'John Lucas Smith' from dual union 3 select 'Kevin Thomas Baco

例如,我有这样的名字:

John Lucas Smith    
Kevin Thomas Bacon
我需要用regexp\u substr或者replace之类的东西来完成它

我想得到的是:

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>
像这样的

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>

尝试使用f_convert函数将字符串拆分为数组,它适用于空格和逗号分隔的字符串。使用f_convert函数将字符串拆分为数组,它适用于空格和逗号分隔的字符串