sql-like

Use LIKE %..% with field values in MySQL

你离开我真会死。 提交于 2019-11-28 16:57:05
I stumbled into a delicate SQL problem when I needed to use a value from a field inside a LIKE %..% statement. Example: SELECT t1.Notes, t2.Name FROM Table1 t1, Table2 t2 WHERE t1.Notes LIKE '%t2.Name%' This is only an example from the top of my head to show what I need to do (I know this will not work). I need to use the value of t2.Name inside the LIKE %..% I guess this is trivial when you know it ;) Use: SELECT t1.Notes, t2.Name FROM Table1 t1 JOIN Table2 t2 ON t1.Notes LIKE CONCAT('%', t2.Name ,'%') NT4.info SELECT t1.a, t2.b FROM t1 JOIN t2 ON t1.a LIKE '%'+t2.b +'%' because the last

SQL- Ignore case while searching for a string

a 夏天 提交于 2019-11-28 16:04:45
问题 I have the following data in a Table PriceOrderShipped PriceOrderShippedInbound PriceOrderShippedOutbound In SQL I need to write a query which searches for a string in a table. While searching for a string it should ignore case. For the below mentioned SQL query SELECT DISTINCT COL_NAME FROM myTable WHERE COL_NAME LIKE '%PriceOrder%' gives all the above data, whereas SELECT DISTINCT COL_NAME FROM myTable WHERE COL_NAME LIKE '%Priceorder%' doesn't give. Eg. when I search for 'PriceOrder' or

Escaping wildcards in LIKE

孤街醉人 提交于 2019-11-28 14:32:00
How do I escape wildcards ( _ and % ) when using a SQL LIKE operator in Oracle? I came to a silly issue today. I need to search for the presence of an underscore _ on a varchar column using LIKE . It doesn't work -- as expected -- since underscores are wildcards according to SQL. Here's my (simpified) code: create table property ( name varchar(20), value varchar(50) ); insert into property (name, value) values ('port', '8120'); insert into property (name, value) values ('max_width', '90'); insert into property (name, value) values ('taxrate%', '5.20'); I tried the following queries in

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

﹥>﹥吖頭↗ 提交于 2019-11-28 14:18:24
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 extremely slow... To be able to use an index for LIKE in SQLite, the table column must have TEXT affinity , i

SQL LIKE with no wildcards the same as '='?

拜拜、爱过 提交于 2019-11-28 13:15:28
I know this is a pretty basic question, and I think I know the answer...but I'd like to confirm. Are these queries truly equivalent? SELECT * FROM FOO WHERE BAR LIKE 'X' SELECT * FROM FOO WHERE BAR ='X' Perhaps there is a performance overhead in using like with no wild cards? I have an app that optionally uses LIKE & wild cards. The SP currently does the like and appends the wild cards -- I am thinking of just updating the query to use like but have the app append the wild cards as needed. CMS As @ocdecio says, if the optimizer is smart enough there should be no difference, but if you want to

PostgreSQL - text Array contains value similar to

六月ゝ 毕业季﹏ 提交于 2019-11-28 12:38:37
I'm trying to get rows where a column of type text[] contains a value similar to some user input. What I've thought and done so far is to use the 'ANY' and 'LIKE ' operator like this: select * from someTable where '%someInput%' LIKE ANY(someColum); But it doesn't work. The query returns the same values as that this query: select * from someTable where 'someInput' = ANY(someColum); I've got good a result using the unnest() function in a subquery but I need to query this in WHERE clause if possible. WHY doesn't the LIKE operator work with the ANY operator and I don't get any errors? I thought

SQLSyntaxErrorException when using LIKE with ojdbc7.jar

吃可爱长大的小学妹 提交于 2019-11-28 12:31:38
I have the following statement : PreparedStatement prpStat = conn .prepareStatement("SELECT * FROM natperson WHERE name LIKE ?"); prpStat.setString(1, "A"); ParameterMetaData pmd = prpStat.getParameterMetaData(); ResultSet rs = prpStat.executeQuery(); and i get the following excepting when i execute the the prpStat.getParameterMetaData(); method with ojdbc7.jar. The exception is not thrown when using ojdbc6. java.sql.SQLSyntaxErrorException: ORA-00904: "NAMEIKE": ungültiger Bezeichner at oracle.jdbc.driver.T4CTTIoer.processError(T4CTTIoer.java:450) at oracle.jdbc.driver.T4CTTIoer.processError

MySQL - Why are COLLATION rules ignored by LIKE operator for German ß character

强颜欢笑 提交于 2019-11-28 12:06:17
I'm running the following select statements on MySQL 5.0.88 with utf8 charset and utf8_unicode_ci collation: SELECT * FROM table WHERE surname = 'abcß'; +----+-------------------+------+ | id | forename | surname | +----+-------------------+------+ | 1 | a | abcß | | 2 | b | abcss | +----+-------------+------------+ SELECT * FROM table WHERE surname LIKE 'abcß'; +----+-------------------+------+ | id | forename | surname | +----+-------------------+------+ | 1 | a | abcß | +----+-------------+------------+ According to http://dev.mysql.com/doc/refman/5.0/en/charset-unicode-sets.html the german

Avoiding SQL Injection in SQL query with Like Operator using parameters?

那年仲夏 提交于 2019-11-28 10:56:21
Taking over some code from my predecessor and I found a query that uses the Like operator: SELECT * FROM suppliers WHERE supplier_name like '%'+name+%'; Trying to avoid SQL Injection problem and parameterize this but I am not quite sure how this would be accomplished. Any suggestions ? note, I need a solution for classic ADO.NET - I don't really have the go-ahead to switch this code over to something like LINQ. try this: var query = "select * from foo where name like @searchterm"; using (var command = new SqlCommand(query, connection)) { command.Parameters.AddWithValue("@searchterm", String

Using LIKE in an Oracle IN clause

喜夏-厌秋 提交于 2019-11-28 10:50:51
I know I can write a query that will return all rows that contain any number of values in a given column, like so: Select * from tbl where my_col in (val1, val2, val3,... valn) but if val1 , for example, can appear anywhere in my_col , which has datatype varchar(300), I might instead write: select * from tbl where my_col LIKE '%val1%' Is there a way of combing these two techniques. I need to search for some 30 possible values that may appear anywhere in the free-form text of the column. Combining these two statements in the following ways does not seem to work: select * from tbl where my_col