想要从数据库中搜索,忽略内容中的空格

时间:2017-03-09 06:16:44

标签: mysql

我想搜索一个键 对自己的不自觉'来自数据库。在数据库中,内容以此形式存在::

它。缠绕本身就是幻觉,因为它发现自己受到结的束缚。

结是sanskaras,缠绕是灵魂。因为灵魂是无意识的

自己作为上帝,它的注意力仍然集中在结上。被释放

我使用以下sql查询来获取结果:

        if (attachmentType == typeof(FormA_Attachment))
        {
            return ((List<FormA_Attachment>) Convert.ChangeType(attachments, typeof(List<FormA_Attachment>))).OfType<GenericAttachment>().ToList();
        }
        else if (attachmentType == typeof(FormB_Attachment))
        ... 
        //similar code

未找到此类记录。原因是,sql函数REPLACE(f.content,&#39;&#39;,&#39;&#39;)按以下格式转换我的内容::

SELECT f.content FROM file_details f WHERE REPLACE(f.content, ' ', '') = REPLACE("unconscious of its own Self", ' ', '');

如果您在更换后看到我的搜索键,那么“unconsciousofitsownSelf&#39;在上面的内容中,您将在两个单独的行中找到它们。这就是为什么我得到的结果是0。

请您为我提供一个解决方案,以便搜索我的密钥,该密钥甚至可以分开存在。

1 个答案:

答案 0 :(得分:0)

搜索数据库中是否存在此单词"unconscious of its own Self"

set @sam = "it. The twine itself is in illusion because it finds itself bound by knots.
The knots are the sanskaras and the twine is the soul. Because the soul is unconscious
of its own Self as God, its attention remains focussed on the knots. To be freed";


select  case when rplace like '%52521325241%' then 'found' else 'not found' end) from 
(SELECT SOUNDEX(@sam) rplace) as a

或者这是第二个选项:

select case when rplace like concat('%',searchChar,'%') then 'found' else 'not found' end,searchChar from
(select SUBSTRING(SOUNDEX('unconscious of its own Self'),2) as searchChar,rplace from 
(SELECT SOUNDEX(@sam) rplace) as a) as b;