在sql中的关键字后从文本中提取字符串? [英] Extract string from a text after a keyword in sql?

查看:55
本文介绍了在sql中的关键字后从文本中提取字符串?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有必要从关键字后面的 SQL 字段中的文本中提取内容.例如,如果我在表中有一个名为 description 的字段,并且该字段的表内容是:

I have the necessity to extract content from a text in a SQL field after a keyword. For example if i have a field called description in a table, and the table content for that field is:

asdasf 关键字狗

asdasf keyword dog

aeee 关键字 cat

aeee keyword cat

ffffaa 关键字狼

ffffaa keyword wolf

我想提取并保存关键字"之后的文本(在本例中为狗、猫和狼)并将其保存在视图中或简单地用选择显示它.谢谢.

I want to extract and save the text after "keyword " (in this case dog,cat and wolf) and save it in a view or simply show it with a select. Thank you.

推荐答案

以下是使用 SUBSTRING() 的示例:

Here is an example using SUBSTRING():

SELECT SUBSTRING(YourField, CHARINDEX(Keyword,YourField) + LEN(Keyword), LEN(YourField))

另一个例子:

declare @YourField varchar(200) = 'Mary had a little lamb'
declare @Keyword varchar(200) = 'had'
select SUBSTRING(@YourField,charindex(@Keyword,@YourField) + LEN(@Keyword), LEN(@YourField) )

结果:

 a little lamb

请注意,此字符串中的 'a' 之前有一个空格.

Please note that there is a space before the 'a' in this string.

这篇关于在sql中的关键字后从文本中提取字符串?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆