sql searching multiple words in a string

前端 未结 8 732
故里飘歌
故里飘歌 2020-12-09 02:35

What is the most efficient and elegant SQL query looking for a string containing the words \"David\", \"Moses\" and \"Robi\". Assume the table is named T an

相关标签:
8条回答
  • 2020-12-09 03:00

    Oracle SQL :

    select * 
    from MY_TABLE
    where REGEXP_LIKE (company , 'Microsodt industry | goglge auto car | oracles    database')
    
    • company - is the database column name.
    • results - this SQL will show you if company column rows contain one of those companies (OR phrase) please note that : no wild characters are needed, it's built in.

    more info at : http://www.techonthenet.com/oracle/regexp_like.php

    0 讨论(0)
  • 2020-12-09 03:02

    if you put all the searched words in a temporaray table say @tmp and column col1, then you could try this:

    Select * from T where C like (Select '%'+col1+'%' from @temp);
    
    0 讨论(0)
  • 2020-12-09 03:09
    Select * from table where 
      columnname like'%David%' and 
      columnname like '%Moses%' and columnname like'%Robi%' 
    
    0 讨论(0)
  • 2020-12-09 03:11

    Here is what I uses to search for multiple words in multiple columns - SQL server

    Hope my answer help someone :) Thanks

    declare @searchTrm varchar(MAX)='one two three ffffd 20   30 comment'; 
    --select value from STRING_SPLIT(@searchTrm, ' ') where trim(value)<>''
    select * from Bols 
    WHERE EXISTS (SELECT value  
        FROM STRING_SPLIT(@searchTrm, ' ')  
        WHERE 
            trim(value)<>''
            and(    
            BolNumber like '%'+ value+'%'
            or UserComment like '%'+ value+'%'
            or RequesterId like '%'+ value+'%' )
            )
    
    0 讨论(0)
  • 2020-12-09 03:11

    If you care about the sequence of the terms, you may consider using a syntax like

    select * from T where C like'%David%Moses%Robi%'
    
    0 讨论(0)
  • 2020-12-09 03:15

    Maybe EXISTS can help.

    and exists (select 1 from @DocumentNames where pcd.Name like DocName+'%' or CD.DocumentName like DocName+'%')
    
    0 讨论(0)
提交回复
热议问题