sql-like

regex in SQL to detect one or more digit

女生的网名这么多〃 提交于 2019-12-01 20:38:39
问题 I have the following query: SELECT * FROM `shop` WHERE `name` LIKE '%[0-9]+ store%' I wanted to match strings that says '129387 store' , but the above regex doesn't work. Why is that? 回答1: Use REGEXP operator instead of LIKE operator Try this: SELECT '129387 store' REGEXP '^[0-9]* store$'; SELECT * FROM shop WHERE `name` REGEXP '^[0-9]+ store$'; Check the SQL FIDDLE DEMO OUTPUT | NAME | |--------------| | 129387 store | 回答2: If you mean MySQL, LIKE does not implement regular expressions. It

regex in SQL to detect one or more digit

别等时光非礼了梦想. 提交于 2019-12-01 19:26:06
I have the following query: SELECT * FROM `shop` WHERE `name` LIKE '%[0-9]+ store%' I wanted to match strings that says '129387 store' , but the above regex doesn't work. Why is that? Use REGEXP operator instead of LIKE operator Try this: SELECT '129387 store' REGEXP '^[0-9]* store$'; SELECT * FROM shop WHERE `name` REGEXP '^[0-9]+ store$'; Check the SQL FIDDLE DEMO OUTPUT | NAME | |--------------| | 129387 store | Barmar If you mean MySQL, LIKE does not implement regular expressions. It implements the much more restricted SQL pattern matching, which just has two special operators: % matches

% confuses python raw sql query

ε祈祈猫儿з 提交于 2019-12-01 19:18:27
问题 Following this SO question, I'm trying to "truncate" all tables related to a certain django application using the following raw sql commands in python: cursor.execute("set foreign_key_checks = 0") cursor.execute("select concat('truncate table ',table_schema,'.',table_name,';') as sql_stmt from information_schema.tables where table_schema = 'my_db' and table_type = 'base table' AND table_name LIKE 'some_prefix%'") for sql in [sql[0] for sql in cursor.fetchall()]: cursor.execute(sql) cursor

Slow search by index query LIKE% MYSQL

守給你的承諾、 提交于 2019-12-01 18:09:26
i have table with 100 000 000 rows so large. Structure of table id int INDEX(not primary not unique just index) lang_index varchar(5) INDEX name varchar(255) INDEX enam varchar(255) INDEX Ok. i do query 1 Query "SELECT name FROM table WHERE lang_index='en' AND name LIKE 'myname%'" Speed is ok for this large table. around 0.02 sec. i try 2 Query "SELECT name FROM table WHERE lang_index='en' AND (name LIKE 'myname%' OR enam LIKE 'myname%')" Very very slow around 230 sec!!! then i try this 3 Query "SELECT name FROM table WHERE lang_index='en' AND enam LIKE 'myname%'" Speed is fantastic. around 0

% confuses python raw sql query

倾然丶 夕夏残阳落幕 提交于 2019-12-01 18:09:19
Following this SO question , I'm trying to "truncate" all tables related to a certain django application using the following raw sql commands in python: cursor.execute("set foreign_key_checks = 0") cursor.execute("select concat('truncate table ',table_schema,'.',table_name,';') as sql_stmt from information_schema.tables where table_schema = 'my_db' and table_type = 'base table' AND table_name LIKE 'some_prefix%'") for sql in [sql[0] for sql in cursor.fetchall()]: cursor.execute(sql) cursor.execute("set foreign_key_checks = 1") Alas I receive the following error: C:\dev\my_project>my_script.py

LINQ to Entities using the SQL LIKE operator

和自甴很熟 提交于 2019-12-01 17:47:26
I have this: query = query.Where(s => s.ShowTypeDescription == showTypeDescription); several times for different variables in order to build dynamic SQL. How would I go about transforming the above to say: query = query.Where(s => s.ShowTypeDescription **LIKE** showTypeDescription); ? If all you want is to find a substring within another string, the best way to do this is with the Contains method: query = query.Where(s => s.ShowTypeDescription.Contains(showTypeDescription)); Because the String.Contains method translates to: CHARINDEX(ShowTypeDescription, @showTypeDescription) > 0 Which is

Oracle execution plans when using the LIKE operator with a DETERMINISTIC function

前提是你 提交于 2019-12-01 12:18:44
Now I have a really tricky thing with Oracle execution plans running havoc, when I use a DETERMINISTIC function on the right hand side of the LIKE operator. This is my situation: The Situation I thought it to be wise to execute a query like this (simplified): SELECT [...] FROM customers cust JOIN addresses addr ON addr.cust_id = cust.id WHERE special_char_filter(cust.surname) like special_char_filter(?) And I would bind ? to something like 'Eder%' . Now customers and addresses are very large tables. That's why it's important to use indexes. Of course, there is a regular index on addresses.cust

LIKE not working in TSQL

眉间皱痕 提交于 2019-12-01 11:09:30
Consider this TSQL : declare @b varchar(100) set @b = 'BANK-41' IF @b LIKE 'BANK_%' BEGIN print 'Wrong Matching' END Why does the TSQL match the string " BANK- " and " BANK_ "? In TSQL the underscore is a wildcard representing a single char. In order to escape in you need to wrap it with square brackets, like this: 'BANK[_]%' See this page: http://www.dirigodev.com/blog/web-development-execution/escaping-percent-and-underscore-characters-in-t-sql-like-clause/ An underscore in SQL Server is reserved for a wild card character, I think. You need to escape it.I think you can put it in brackets: %[

Full Text Search and LIKE statement

生来就可爱ヽ(ⅴ<●) 提交于 2019-12-01 11:04:50
Does the GAE experimental Full Text Search API provide an alternative to the SQL "LIKE statement"? Thanks! No. The SQL like statement supports arbitrary substring matching - for instance, "abbatton" will be a match for "bat" - while fulltext search implements full text indexing , which uses normalization, stemming, and an inverted index to construct an index that is good at answering the sort of queries users tend to enter for textual documents. If you mean "does the Full Text search API provide an alternative for what SQL's LIKE operator is commonly (mis)used for", the answer is yes - since

how to select record whose matching percentage is higher than other using like operator in sql server?

冷暖自知 提交于 2019-12-01 10:54:13
I have set of records which I need to search using criteria. But criteria is returning me multiple rows. So I need top 2 records which are having maximum percentage of criteria matching. I worked on fuzzy logic but found that it is too complex for such simple problems. I have scenarios like below: SELECT DISTINCT FirstName, LastName, CountryName, StateName FROM Employee Say for example above one is returning me 5 records. What I want is like use "like" operator thru which I can find that statename like '%Gujarat%' & countryname like '%India%' matching percentage with above five records. Once I