sql-like

Sql Like to RegEx

若如初见. 提交于 2019-11-29 13:31:43
Is there a good way to convert Regular Expression into LIKE inside a Function (MSSQL)? The sproc does not get more complicated than this: (country\=)(?<Country>[\w\d]+)(\&sessionid\=)(?<SessionId>.+) The groups will not be used in the LIKE, they are there for another purpose. I would like to use this inside a sproc late like: SELECT * FROM [Table] WHERE test_regex(regex, 'text') = 1 Where the regex is a part of [Table] It is possible to add Regular Expression parsing to SQL server, using a CLR function. This is possible from SQL 2005 and up. See here for a great example. I'd imagine SELECT ...

How to escape string while matching pattern in PostgreSQL

白昼怎懂夜的黑 提交于 2019-11-29 12:10:41
I want to find rows where a text column begins with a user given string, e.g. SELECT * FROM users WHERE name LIKE 'rob%' but "rob" is unvalidated user input. If the user writes a string containing a special pattern character like "rob_", it will match both "robert42" and "rob_the_man". I need to be sure that the string is matched literally, how would I do that? Do I need to handle the escaping on an application level or is it a more beautiful way? I'm using PostgreSQL 9.1 and go-pgsql for Go. The _ and % characters have to be quoted to be matched literally in a LIKE statement, there's no way

Why I need to double-escape (use 4 \\) to find a backslash ( \\ ) in pure SQL?

[亡魂溺海] 提交于 2019-11-29 11:22:28
I do not understand this MySQL behaviour : if I want to display a\b, I can just select "a\\b" which work without problem : mysql> select "a\\b"; +-----+ | a\b | +-----+ | a\b | +-----+ 1 row in set (0.05 sec) But if I wnat to search a string containing a \ in a table using LIKE, I need to double-escape my "\". Why ? Here is an example. We prepare a small table. create table test ( test varchar(255) ); insert into test values ( "a\\b" ) , ( "a\\b\\c" ) , ( "abcd" ); mysql> select * from test; +-------+ | test | +-------+ | a\b | | a\b\c | | abcd | +-------+ 3 rows in set (0.05 sec) We try to

Match '%' sign when searching in MySQL database

烈酒焚心 提交于 2019-11-29 10:46:06
I would like to match this 'wildcard %' in MySQL. I tried using escape \% and it is not working. The default escape character is \ . So just prefix % with a \ as: \% : The manual clearly says: To test for literal instances of a wild-card character, precede it by the escape character. If you do not specify the ESCAPE character, “\” is assumed. Search for % in Stack%Overflow : mysql> select 'Stack%Overflow' like '%\%%'; +------------------------------+ | 'Stack%Overflow' like '%\%%' | +------------------------------+ | 1 | <----- Found +------------------------------+ 1 row in set (0.00 sec)

Hive - LIKE Operator

限于喜欢 提交于 2019-11-29 10:01:18
问题 I can not figure out how I deal with that problem: This is my Data: Table1: Table2: BRAND PRODUCT SOLD Sony Sony ABCD 1233 Apple Sony adv 1233 Google Sony aaaa 1233 IBM Apple 123 1233 etc. Apple 345 1233 IBM 13123 1233 Is it possible to filter the query that I have a table where stands the brand and the total solds? My idea is: Select table1.brand, sum(table2.sold) from table1 join table2 on (table1.brand LIKE '%table2.product%') group by table.1.brand That was my idea, but i always get an

LIKE and NULL in WHERE clause in SQL

别来无恙 提交于 2019-11-29 09:23:42
I have a store procedure which i have planned to use for search and get all values. Scenario: If the parameter passed is NULL it should return all the values of the table and if the parameter passed is not NULL it should return the values according to the condition which is in LIKE. //Query: ALTER procedure [dbo].[usp_GetAllCustomerDetails] ( @Keyword nvarchar(20) = null ) As Begin Select CustomerId,CustomerName,CustomerTypeName,CustomerCode,CategoryName,CustomerMobile,CustomerEmail,CustomerAddress,CustomerCity,CustomerState,Pincode from tblCustomerMaster CM inner join dbo

Accent and case insensitive collation in Oracle with LIKE

隐身守侯 提交于 2019-11-29 04:50:41
I have found this answer useful: Accent and case insensitive COLLATE equivalent in Oracle , but my question is regarding LIKE searching with a version 9 Oracle db. I have tried a query like this: SELECT column_name FROM table_name WHERE NLSSORT(column_name, 'NLS_SORT = Latin_AI') LIKE NLSSORT('%somethingInDB%', 'NLS_SORT = Latin_AI') but no results are ever returned. I created a little Java file to test: import org.apache.commons.dbcp.BasicDataSource; import java.sql.Connection; import java.sql.SQLException; import java.sql.PreparedStatement; import java.sql.ResultSet; public class

SQL 'LIKE' operator in Hibernate Criteria API

放肆的年华 提交于 2019-11-29 03:41:39
I want to implement some universal filter with Hibernate Criteria . It should work like LIKE operator from SQL: SELECT * FROM table WHERE table.ANYCOLOUMNHERE LIKE '%'||anyvaluehere||'%' I have Map<String, String> where key is a column name, and value is its value. I tried something like this: for (Entry<String, String> filter : filters.entrySet()) { crit.add(Restrictions.ilike(filter.getKey(), filter.getValue(), MatchMode.ANYWHERE)); } But when field type is not String , it causes java.lang.ClassCastException : [com.nsn.util.LoggerUtilerror] (http-localhost-127.0.0.1-8080-1) Error while

MySQL like another field

你离开我真会死。 提交于 2019-11-29 01:50:23
问题 I have a table with two string columns: Url and ModelId. I need to return records for which Url contains ModelId, something like this: SELECT Id, Url, ModelId WHERE Url like "%ModelId%" 回答1: SELECT Id, Url, ModelId WHERE Url LIKE CONCAT('%', ModelId, '%') 回答2: You can not just concat the strings, you must also escape the field from % and _: SELECT Id, Url, ModelId WHERE Url LIKE CONCAT('%', REPLACE(REPLACE(ModelId,'%','\%'),'_','\_'), '%'), '%') 回答3: Here is the query: SELECT Id, Url, ModelId

“Like” operator in inner join in SQL

不羁岁月 提交于 2019-11-29 01:50:13
Using Sequel Pro, I have these two tables: Table1 Name Year x y John Smith 2010 10 12 Adam Jones 2010 8 13 John Smith 2011 7 15 Adam Jones 2011 9 14 etc. and Table2 Name Year z Smith John Smith John 2010 27 Jones Adam Jones Adam 2010 25 Smith John Smith John 2011 29 Jones Adam Jones Adam 2011 21 etc. Basically, the names in Table2 are the same only with the last name and first name switched, then repeated once. So the Names in Table1 are found in the names of Table2 ("John Smith" is found in "Smith John Smith John"). I want to perform an inner join and connect the z value of Table2 to the