sql-like

Does wildcard in left-most column of composite index mean remaining columns in index aren't used in index lookup (MySQL)?

£可爱£侵袭症+ 提交于 2019-12-02 07:42:42
Imagine you have a primary composite index of last_name,first_name . Then you performed a search of WHERE first_name LIKE 'joh%' AND last_name LIKE 'smi%' . Does the wildcard used in the last_name condition mean that the first_name condition will not be used in further helping MySQL find indexes? In other words, by putting a wildcard on the last_name condition MySQL will only do a partial index lookup (and ignores conditions given in the columns that are to the right of last_name)? Further clarification of what I'm asking Example-1: Primary key is last_name, first_name . Example-2: Primary key

Oracle: merging two different queries into one, LIKE & IN

橙三吉。 提交于 2019-12-02 06:09:24
问题 I need to implement a search query, where we have multiple filters(values) for a single column in database(oracle). But these multiple filters(values) are LIKE query parameters. I am not sure that whether I am visioning correct result using the approach in mind. I want something that should work like: departmentname IN ( LIKE '%Medi%', LIKE '%Ciga%') I know it will not work, just I want to show the vision I am having. Though we all know that its simple using foreach and manually adding 'OR'

Order of LIKE clause in query when wanting to use multiple terms

谁都会走 提交于 2019-12-02 05:26:33
I have the query SELECT * FROM images WHERE tags LIKE '%example%hello%' I would like the database to select rows which have 'example' and 'hello' in the 'tags' column in any order, as in: A row with 'hello, test, example', also 'example, hello, test' or any other variation of this order. Is this possible, even without using LIKE? The rows must all contain everything specified with LIKE. EDIT: Such as, when I provide 'example' and 'hello' in the query, rows returned must contain both 'example' and 'hello'. You could try a simple OR for a quick solution: SELECT * FROM images WHERE tags LIKE '

Empty string variable matching to LIKE conditions in SQL

▼魔方 西西 提交于 2019-12-02 05:20:17
I have a SQL Server table containing a nvarchar(max) column. I ran a query to select every row where this column contains the string 'remove'. Amongst the results, I have several rows where this column is populated with an empty string and I don't understand why these values have been returned. I tried to investigate further, on one of the empty string values returned. I found that the empty string value would match to certain LIKE conditions, but not others. For instance, it will match to '%remove%' and '%x%', but it won't match to '%q%'. Within the results grid on SQL Server Management

oci_bind_by_name doesn't work with LIKE clause

不想你离开。 提交于 2019-12-02 04:27:19
问题 My code is something like this: $s = ociparse($conn, "SELECT u.email, u.city FROM tickets t, users u WHERE t.userId = u.userId AND u.city LIKE '%:city%'"); $city = $_GET['city']; oci_bind_by_name($s, ":city", $city); Apparently, it can't replace the ":city" The warning I get: Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\phpOracle\tickets.php on line 41 回答1: You need to bind it like this, you have to concatenate the % signs with it and you cannot have

MySQL Search String with Spaces Using LIKE

时光毁灭记忆、已成空白 提交于 2019-12-02 02:55:23
问题 I'm building a search on my site and I noticed it doesn't work when you enter more than one word into the search. Here's the gist of the query: SELECT * FROM `blog` WHERE `content` LIKE '%$keyword%' OR `title` LIKE '%$keyword%' ORDER BY `id` DESC The weird things is that when I test the query in phpMyAdmin it returns the expected results. On my website however, no results are found. I tried replacing spaces in the keyword with %s, but that didn't change anything. 回答1: The problem is that LIKE

Escape underscore in PL/SQL

大兔子大兔子 提交于 2019-12-02 00:37:38
问题 I have an oracle trigger similar to this: AFTER INSERT OR UPDATE ON TABLE_ABC FOR EACH ROW BEGIN IF (:new.COLUMN_A LIKE '%_H') THEN INSERT INTO TABLE_DEF (ID, COLUMN_B) VALUES (SEQ_DEF.NEXTVAL, :new.COLUMN_B); END IF; END; Now I want to escape the underscore in the like clause so that only values such as 'ABCD_H' or '1234_H' in COLUMN_A are processed by this trigger but not values such as '1234H'. How can I achieve that for the given example? 回答1: You can use the escape clause: if :new.column

Convert date to string in Hibernate Criteria

耗尽温柔 提交于 2019-12-02 00:01:03
Is it possible to perform a request that checks the string representation of a Date instance. For example Restrictions.like("dateField", "%12%") to retrieve dates that either have String 12 in day or 12 in month or 12 in year where "dateField" is an instance of java.util.Date Thanks I had the same problem and here's what I did: First, I created my own Criterion implementation: public class DateLikeExpression implements Criterion { private static final long serialVersionUID = 1L; private String propertyName; private String value; public DateLikeExpression(String propertyName, String value) {

oci_bind_by_name doesn't work with LIKE clause

▼魔方 西西 提交于 2019-12-01 23:04:29
My code is something like this: $s = ociparse($conn, "SELECT u.email, u.city FROM tickets t, users u WHERE t.userId = u.userId AND u.city LIKE '%:city%'"); $city = $_GET['city']; oci_bind_by_name($s, ":city", $city); Apparently, it can't replace the ":city" The warning I get: Warning: oci_bind_by_name(): ORA-01036: illegal variable name/number in C:\xampp\htdocs\phpOracle\tickets.php on line 41 You need to bind it like this, you have to concatenate the % signs with it and you cannot have your bound variable wrapped in single quotes: $s = ociparse($conn, "SELECT u.email, u.city FROM tickets t,

Use of LIKE clause in sql prepared statement, spring, SimpleJDBCTemplate

匆匆过客 提交于 2019-12-01 20:39:54
I have the following sql prepared statement: SELECT * FROM video WHERE video_name LIKE ? Im using spring and jdbc. i have a method, where term is a searchterm, sjt is a SimpleJdbcTemplate, VideoMapper is a RowMapper and searchForTermQuery is the string from above ... return sjt.query(searchForTermQuery, new VideoMapper(), term); My table has 2 videos that match the term. However when I run the query none is found. I get an empty List. I tried playing with % around the question mark, but it only gave badGrammarExceptions. You need to put the % around the value itself, not around the placeholder