sql-like

how to safely generate a SQL LIKE statement using python db-api

守給你的承諾、 提交于 2019-11-27 22:54:38
I am trying to assemble the following SQL statement using python's db-api: SELECT x FROM myTable WHERE x LIKE 'BEGINNING_OF_STRING%'; where BEGINNING_OF_STRING should be a python var to be safely filled in through the DB-API. I tried beginningOfString = 'abc' cursor.execute('SELECT x FROM myTable WHERE x LIKE '%s%', beginningOfString) cursor.execute('SELECT x FROM myTable WHERE x LIKE '%s%%', beginningOfString) I am out of ideas; what is the correct way to do this? It's best to separate the parameters from the sql if you can. Then you can let the db module take care of proper quoting of the

How do I find ' % ' with the LIKE operator in SQL Server? [duplicate]

自闭症网瘾萝莉.ら 提交于 2019-11-27 21:52:00
This question already has an answer here: How do I escape a percentage sign in T-SQL? 3 answers I have a column name Address which consists of some address which has '%' in between as: Address -------------------- Aman Ja%lan% Stree% Ro%ad etc., etc. How I can write the LIKE operator to find that pattern? I tried: declare @var char(1) set @var='!%' select Address from Accomodation where Address like '%'+@var+'%' I would use WHERE columnName LIKE '%[%]%' SQL Server stores string summary statistics for use in estimating the number of rows that will match a LIKE clause. The cardinality estimates

Using OR in LIKE Query in MySQL to compare multiple fields

ⅰ亾dé卋堺 提交于 2019-11-27 21:20:38
I always thought that you could use OR in a LIKE statment to query things in MySQL. So, if I wanted to compare multiple fields in a row to 1 keyword or term: SELECT * FROM MyTable WHERE Column1 OR Column2 LIKE '%keyword%'; and if I had an array of words to compare: SELECT * FROM MyTable WHERE Column1 OR Column2 LIKE '%keyword1%' AND Column1 OR Column2 LIKE '%keyword2%'; I don't believe that syntax is correct, however. Is there an efficient method of writing this aside from something like: SELECT * FROM MyTable WHERE Column1 LIKE '%keyword1%' OR Column2 LIKE '%keyword1%' AND Column1 LIKE '

SQL LIKE % inside array

我怕爱的太早我们不能终老 提交于 2019-11-27 20:08:09
I know how to perform an SQL LIKE % query for a single value like so: SELECT * FROM users WHERE name LIKE %tom%; but how do I do this if the search terms for my LIKE comes from an array? For example, let's say we have an array like this: $words = array("Tom", "Smith", "Larry"); How do I perform my SQL LIKE % to search for the words in my array like: SELECT * FROM users WHERE name LIKE %[each_element_from_my_array]% WITHOUT putting the whole query inside a foreach loop or something EDIT : I forgot to mention that I'm doing this in cakePHP inside the conditions of the cakePHP find('all') method,

SQL 'LIKE' query using '%' where the search criteria contains '%'

别说谁变了你拦得住时间么 提交于 2019-11-27 20:02:22
I have an SQL query as below. Select * from table where name like '%' + search_criteria + '%' If search_criteria = 'abc', it will return data containing xxxabcxxxx which is fine. But if my search_criteria = 'abc%', it will still return data containing xxxabcxxx , which should not be the case. How do I handle this situation? If you want a % symbol in search_criteria to be treated as a literal character rather than as a wildcard, escape it to [%] ... where name like '%' + replace(search_criteria, '%', '[%]') + '%' The easiest solution is to dispense with "like" altogether: Select * from table

Can the LIKE statement be optimized to not do full table scans?

旧街凉风 提交于 2019-11-27 19:36:56
问题 I want to get a subtree from a table by tree path. the path column stores strings like: foo/ foo/bar/ foo/bar/baz/ If I try to select all records that start with a certain path: EXPLAIN QUERY PLAN SELECT * FROM f WHERE path LIKE "foo/%" it tells me that the table is scanned, even though the path column is indexed :( Is there any way I could make LIKE use the index and not scan the table? I found a way to achieve what I want with closure table, but it's harder to maintain and writes are

Accent and case insensitive collation in Oracle with LIKE

为君一笑 提交于 2019-11-27 18:40:58
问题 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 query for a carriage return in a string and ultimately removing carriage return

浪尽此生 提交于 2019-11-27 18:06:35
SQL query for a carriage return in a string and ultimately removing carriage return I have some data in a table and there are some carriage returns in places where I don't want them. I am trying to write a query to get all of the strings that contain carriage returns. I tried this select * from Parameters where Name LIKE '%"\n" %' Also select * from Parameters where Name LIKE '\r' ' Both are valid SQL but are not returning what I am looking for. Do I need to use the Like command or a different command? How do I get the carriage return into the query? The carriage return is not necessarily at

Using Eloquent ORM in Laravel to perform search of database using LIKE

陌路散爱 提交于 2019-11-27 17:46:24
I want to use Eloquent's active record building to build a search query, but it is going to be a LIKE search. I have found the User::find($term) or User::find(1) , but this is not generating a like statement. I'm not looking for a direct answer, but if someone could at least give me a direction to look in that'd be great! You're able to do database finds using LIKE with this syntax: Model::where('column', 'LIKE', '%value%')->get(); If you need to frequently use LIKE, you can simplify the problem a bit. A custom method like () can be created in the model that inherits the Eloquent ORM: public

SQL 'LIKE' operator in Hibernate Criteria API

ε祈祈猫儿з 提交于 2019-11-27 17:42:08
问题 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