您可以使用 REGEXP_SUBSTR 用更短的代码来实现。
例如,
SQL> WITH sample_data AS(
2 SELECT 'Command triggerEvent started' str FROM dual UNION ALL
3 SELECT 'Command stopService stopped' str FROM dual UNION ALL
4 SELECT 'Command startService started' str FROM dual UNION ALL
5 SELECT 'Command executeCommand running' str FROM dual
6 )
7 -- end of sample_data mocking as real table
8 SELECT trim(regexp_substr(str, '[^ ]+', 1, 2)) command
9 FROM sample_data;
COMMAND
------------------------------
triggerEvent
stopService
startService
executeCommand
当然,最好使用 SUBSTR 和 INSTR,因为它们的 CPU 密集度 仍然比 快正则表达式。
SQL> WITH sample_data AS(
2 SELECT 'Command triggerEvent started' str FROM dual UNION ALL
3 SELECT 'Command stopService stopped' str FROM dual UNION ALL
4 SELECT 'Command startService started' str FROM dual UNION ALL
5 SELECT 'Command executeCommand running' str FROM dual
6 )
7 -- end of sample_data mocking as real table
8 SELECT trim(SUBSTR(str, instr(str, ' ', 1, 1),
9 instr(str, ' ', 1, 2) - instr(str, ' ', 1, 1))
10 ) command
11 FROM sample_data;
COMMAND
------------------------------
triggerEvent
stopService
startService
executeCommand