mysql检索部分列 [英] mysql retrieve partial column

查看:68
本文介绍了mysql检索部分列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用TinyMCE,以允许用户编写最终将提交到数据库的内容.

I am using TinyMCE to allow users to write in what will eventually be submitted to a database.

TinyMCE包含一个按钮,该按钮将插入分页符"(实际上只是HTML注释<!--pagebreak-->).

TinyMCE includes a button which will insert a "pagebreak" (actually just an HTML comment <!--pagebreak-->).

以后我如何才能将所有内容拉回至首次出现的分页符标记"?该标记后可能有大量数据,以后我可以通过php丢弃这些数据,但看来我什至不应该将其带回来.因此,如果我不知道<!--pagebreak-->对数据有多远,我可以SELECT只是列的一部分吗?

How can I later pull back everything up to the first occurrence of the pagebreak "tag"? There might be a significant bit of data after that tag which I could discard via php later, but it seems like I shouldn't even bring it back. So I can I SELECT just part of a column if I never know how far in to the data the <!--pagebreak--> will be?

下面的答案确实有效,并且可以让我到达需要去的地方..我很好奇是否有同样简单的方法来处理整列,如果它很短,那么分页符不存在.使用以下解决方案,如果找不到分页符,则返回一个空字符串.

The below answer does work, and will get me where I need to go.. I am just curious as to if there is an equally simple way to handle bringing back the whole column if it is short and thus the pagebreak tag doesn't exist. With the below solution, if no pagebreak is found, an empty string is returned.

如果没有,那么我可以在代码中轻松地处理它.

If not, then I can easily handle it in the code.

推荐答案

像这样的事情应该使您一切都达到<!--:

Something like this should get you everything up to the <!--:

SELECT SUBSTRING(my_col FROM 1 FOR POSITION('<!--' IN my_col)-1) AS a_chunk 
  FROM my_table

有关字符串函数的参考.


只需将OMG Ponies的单词放入SQL:


Just putting OMG Ponies' words into SQL:

SELECT CASE WHEN position('<!--' IN my_col) > 0 
            THEN SUBSTRING(my_col FROM 1 FOR POSITION('<!--' IN my_col)-1)
            ELSE my_col END AS a_chunk
  FROM my_table

听起来您还需要检查文本的长度;是否有分页符.您可以使用CHARACTER_LENGTH().

It sounds like you'll also want a check on the length of the text; whether or not there is a page break. You can use CHARACTER_LENGTH() for that.

这篇关于mysql检索部分列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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