[英]How to SELECT a field without the first n characters and the last m characters?
I have a SELECT statement that is trying to view data from a single table. 我有一个SELECT语句正在尝试从单个表中查看数据。 The data is encapsulated by HTML tags (
<p>
and </p>
). 数据由HTML标记(
<p>
和</p>
)封装。 For instance, one field might say: 例如,一个字段可能会说:
<p>Lorem Ipsum</p>
How do I tell the SELECT statement to discount the first 3 characters and the last 4 characters? 如何告诉SELECT语句将前3个字符和后4个字符打折?
SELECT SUBSTRING(data, 4, LENGTH(data)-7)
If all data has only one opening tag at the beginning, and one closing tag at the end, like in your example, you could use this: 如果所有数据的开头都只有一个开始标记,而结尾处只有一个结束标记(例如您的示例),则可以使用以下代码:
select
case when instr(data, '</')>instr(data, '>') then
substring(data, instr(data, '>')+1,instr(data, '</')-instr(data, '>')-1)
else
data
end as stripped_data
from
your_table
notice that this will strip also unmatched tags like <p>Lorem Ipsum</strong>
请注意,这也会去除不匹配的标签,例如
<p>Lorem Ipsum</strong>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.