sql-like

implement LIKE query in PDO

蓝咒 提交于 2019-11-26 04:22:06
问题 I am running problems in implementing LIKE in PDO I have this query: $query = \"SELECT * FROM tbl WHERE address LIKE \'%?%\' OR address LIKE \'%?%\'\"; $params = array($var1, $var2); $stmt = $handle->prepare($query); $stmt->execute($params); I checked the $var1 and $var2 they contain both the words I want to search, my PDO is working fine since some of my queries SELECT INSERT they work, it\'s just that I am not familiar in LIKE here in PDO. The result is none returned. Do my $query is

List of special characters for SQL LIKE clause

断了今生、忘了曾经 提交于 2019-11-26 03:48:36
问题 What is the complete list of all special characters for a SQL (I\'m interested in SQL Server but other\'s would be good too) LIKE clause? E.g. SELECT Name FROM Person WHERE Name LIKE \'%Jon%\' SQL Server: % _ [specifier] E.g. [a-z] [^specifier] ESCAPE clause E.g. %30!%%\' ESCAPE \'!\' will evaluate 30% as true \' characters need to be escaped with \' E.g. they\'re becomes they\'\'re MySQL: % - Any string of zero or more characters. _ - Any single character ESCAPE clause E.g. %30!%%\' ESCAPE \

How can I search (case-insensitive) in a column using LIKE wildcard?

淺唱寂寞╮ 提交于 2019-11-26 01:45:00
问题 I looked around some and didn\'t find what I was after so here goes. SELECT * FROM trees WHERE trees.`title` LIKE \'%elm%\' This works fine, but not if the tree is named Elm or ELM etc... How do I make SQL case insensitive for this wild-card search? I\'m using MySQL 5 and Apache. 回答1: SELECT * FROM trees WHERE trees.`title` COLLATE UTF8_GENERAL_CI LIKE '%elm%' Actually, if you add COLLATE UTF8_GENERAL_CI to your column's definition, you can just omit all these tricks: it will work

Combining “LIKE” and “IN” for SQL Server [duplicate]

扶醉桌前 提交于 2019-11-26 01:12:44
问题 This question already has answers here : Is there a combination of “LIKE” and “IN” in SQL? (23 answers) Closed 6 years ago . Is it possible to combine LIKE and IN in a SQL Server-Query? So, that this query SELECT * FROM table WHERE column LIKE IN (\'Text%\', \'Link%\', \'Hello%\', \'%World%\') Finds any of these possible matches: Text, Textasd, Text hello, Link2, Linkomg, HelloWorld, ThatWorldBusiness etc... 回答1: Effectively, the IN statement creates a series of OR statements... so SELECT *

php mysqli prepared statement LIKE

徘徊边缘 提交于 2019-11-26 00:09:55
问题 How can I with mysqli make a query with LIKE and get all results? This is my code but it dosn\'t work: $param = \"%{$_POST[\'user\']}%\"; $stmt = $db->prepare(\"SELECT id,Username FROM users WHERE Username LIKE ?\"); $stmt->bind_param(\"s\", $param); $stmt->execute(); $stmt->bind_result($id,$username); $stmt->fetch(); This code it doesn\'t seem to work. I have searched it a lot. Also it may return more than 1 row. So how can I get all the results even if it returns more than 1 row? 回答1: Here

Case insensitive searching in Oracle

北慕城南 提交于 2019-11-25 23:52:36
问题 The default behaviour of LIKE and the other comparison operators, = etc is case-sensitive. Is it possible make them case-insensitive? 回答1: Since 10gR2, Oracle allows to fine-tune the behaviour of string comparisons by setting the NLS_COMP and NLS_SORT session parameters: SQL> SET HEADING OFF SQL> SELECT * 2 FROM NLS_SESSION_PARAMETERS 3 WHERE PARAMETER IN ('NLS_COMP', 'NLS_SORT'); NLS_SORT BINARY NLS_COMP BINARY SQL> SQL> SELECT CASE WHEN 'abc'='ABC' THEN 1 ELSE 0 END AS GOT_MATCH 2 FROM DUAL

How can I escape square brackets in a LIKE clause?

妖精的绣舞 提交于 2019-11-25 23:40:24
问题 I am trying to filter items with a stored procedure using like. The column is a varchar(15). The items I am trying to filter have square brackets in the name. For example: WC[R]S123456 . If I do a LIKE \'WC[R]S123456\' it will not return anything. I found some information on using the ESCAPE keyword with LIKE but I do not understand how to use it to treat the square brackets as a regular string. 回答1: LIKE 'WC[[]R]S123456' or LIKE 'WC\[R]S123456' ESCAPE '\' Should work. 回答2: Let's say you want

Equals(=) vs. LIKE

只谈情不闲聊 提交于 2019-11-25 23:39:59
问题 When using SQL, are there any benefits of using = in a WHERE clause instead of LIKE ? Without any special operators, LIKE and = are the same, right? 回答1: Different Operators LIKE and = are different operators. Most answers here focus on the wildcard support, which is not the only difference between these operators! = is a comparison operator that operates on numbers and strings. When comparing strings, the comparison operator compares whole strings . LIKE is a string operator that compares

How to do SQL Like % in Linq?

若如初见. 提交于 2019-11-25 23:36:16
问题 I have a procedure in SQL that I am trying to turn into Linq: SELECT O.Id, O.Name as Organization FROM Organizations O JOIN OrganizationsHierarchy OH ON O.Id=OH.OrganizationsId where OH.Hierarchy like \'%/12/%\' The line I am most concerned with is: where OH.Hierarchy like \'%/12/%\' I have a column that stores the hierarchy like /1/3/12/ for example so I just use %/12/% to search for it. My question is, what is the Linq or .NET equivalent to using the percent sign? 回答1: .Where(oh => oh

How to query MongoDB with “like”?

偶尔善良 提交于 2019-11-25 22:16:22
问题 I want to query something with SQL\'s like query: SELECT * FROM users WHERE name LIKE \'%m%\' How to do I achieve the same in MongoDB? I can\'t find an operator for like in the documentation. 回答1: That would have to be: db.users.find({"name": /.*m.*/}) or, similar: db.users.find({"name": /m/}) You're looking for something that contains "m" somewhere (SQL's ' % ' operator is equivalent to Regexp's ' .* '), not something that has "m" anchored to the beginning of the string. note: mongodb uses