如何 select 某个词组后的下一个词? - 红移 SQL
How to select next word after certain phrase? - Redshift SQL
假设我有一个文本类似于以下内容的字段:
{random text here} ABC DEF {my_variable_length_keyword} {random text here}
select{my_variable_length_keyword}
最简单的方法是什么?
我试过类似的方法:
select
substring(my_field, charindex('ABC DEF', my_field) + len('ABC DEF'),
len(my_field) - (charindex('ABC DEF', my_field) + len('ABC DEF')))
from my_table
任何帮助都会很棒。
使用 substring
和正则表达式。
select substring(my_field from 'ABC DEF ([a-zA-Z]+)') from my_table;
这是一个插图。
select substring
(
'{random text here} ABC DEF MyVarLenKwd {random text here}'
from 'ABC DEF ([a-zA-Z]+)'
);
-- Result: MyVarLenKwd
SELECT trim('ABC DEF ' FROM regexp_substr(my_field, 'ABC DEF ([^ ]+)'))
FROM my_table
假设我有一个文本类似于以下内容的字段:
{random text here} ABC DEF {my_variable_length_keyword} {random text here}
select{my_variable_length_keyword}
最简单的方法是什么?
我试过类似的方法:
select
substring(my_field, charindex('ABC DEF', my_field) + len('ABC DEF'),
len(my_field) - (charindex('ABC DEF', my_field) + len('ABC DEF')))
from my_table
任何帮助都会很棒。
使用 substring
和正则表达式。
select substring(my_field from 'ABC DEF ([a-zA-Z]+)') from my_table;
这是一个插图。
select substring
(
'{random text here} ABC DEF MyVarLenKwd {random text here}'
from 'ABC DEF ([a-zA-Z]+)'
);
-- Result: MyVarLenKwd
SELECT trim('ABC DEF ' FROM regexp_substr(my_field, 'ABC DEF ([^ ]+)'))
FROM my_table