sql-like

PostgreSQL: Select data with a like on timestamp field

为君一笑 提交于 2019-12-29 11:46:08
问题 I am trying to select data from a table, using a "like" on date field "date_checked" (timestamp). But I have this error : SQLSTATE[42883]: Undefined function: 7 ERROR: operator does not exist: timestamp without time zone My request is : SELECT my_table.id FROM my_table WHERE my_table.date_checker LIKE '2011-01-%' I don't want to use : SELECT my_table.id FROM my_table WHERE my_table.date_checker >= '2011-01-01 00:00:00' AND my_table.date_checker < '2011-02-01 00:00:00' 回答1: It's all very well

What does \ (backslash) mean in an SQL query?

感情迁移 提交于 2019-12-29 06:24:14
问题 I have the following query SELECT txt1 FROM T1 WHERE txt1 LIKE '_a\%' will that result in answers that have any char+a+\+whatever? is something like Pa\pe valid as a result? are Ca% or _a% valid answers maybe? how does \ behave normally inside an SQL query?? 回答1: % is a wildcard character that matches zero or more characters in a LIKE clause. _ is a wildcard character that maches exactly one character in a LIKE clause. \ is a special character known as an escape character that indicates that

SQLSyntaxErrorException when using LIKE with ojdbc7.jar

一笑奈何 提交于 2019-12-29 00:07:09
问题 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

Like operator for integer

做~自己de王妃 提交于 2019-12-28 13:35:38
问题 I have a column of type bigint (ProductSerial) in my table. I need to filter the table by the Product serial using like operator. But I found that, like operator can't be used for integer type. Is there any other method for this (I don't want to use the = operator). 回答1: If you must use LIKE , you can cast your number to char / varchar , and perform the LIKE on the result. This is quite inefficient, but since LIKE has a high potential of killing indexes anyway, it may work in your scenario: .

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

我只是一个虾纸丫 提交于 2019-12-28 05:56:15
问题 This question already has answers here : How do I escape a percentage sign in T-SQL? (3 answers) Closed 6 years ago . 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+'%' 回答1: I would use WHERE columnName LIKE '%[%]%' SQL Server

Match only entire words with LIKE?

我是研究僧i 提交于 2019-12-28 03:53:24
问题 So 'awesome document' LIKE '%doc%' is true, because doc is a sub-string. But, I want it to be false while 'awesome doc' or 'doc awesome' or 'awesome doc awesome' should be true. How can I do with with a like? I'm using sqlite, so I hope I don't have to use something that isn't available. 回答1: How about split it into four parts - [MyColumn] Like '% doc %' OR [MyColumn] Like '% doc' OR [MyColumn] Like 'doc %' OR [MyColumn] = 'doc' Edit: An alternate approach (only for ascii chars) could be: '#'

Cannot use a LIKE query in a JDBC PreparedStatement?

大兔子大兔子 提交于 2019-12-28 02:44:08
问题 The query code and query: ps = conn.prepareStatement("select instance_id, ? from eam_measurement where resource_id in (select RESOURCE_ID from eam_res_grp_res_map where resource_group_id = ?) and DSN like '?' order by 2"); ps.setString(1,"SUBSTR(DSN,27,16)"); ps.setInt(2,defaultWasGroup); ps.setString(3,"%Module=jvmRuntimeModule:freeMemory%"); rs = ps.executeQuery(); while (rs.next()) { bla blah blah blah ... Returns an empty ResultSet . Through basic debugging I have found its the third bind

MySQL PDO query LIKE with PIPES

主宰稳场 提交于 2019-12-25 17:15:25
问题 I have a PDO statement which is supposed to look for data with pipes around it, I have multiple id's stored in a single column. I know this isn't great but it seems the logical way to store the data. Column content example |1|3|4|5|14|76| So I want to find every line in the database with 3 in it. I use a php form to post or get 3 $getthis = $_GET['getthis']; $sql = "SELECT * FROM table WHERE types LIKE '?' ORDER BY name"; $q = $conn->prepare($sql); $q->execute('%|$getthis|%'); while ($data =

LIKE query on values of Map ElementCollection in entity in HQL

跟風遠走 提交于 2019-12-25 16:38:30
问题 I have an entity named « Form » that contains a Map « details » of (key/value)=(language code/translation) : @Entity class Form { : @ElementCollection(fetch = FetchType.EAGER) @MapKeyColumn(name = "language", length = 50, nullable = false) @MapKeyEnumerated(EnumType.STRING) @Column(name = "value", length = 150) private final Map<Language, String> details = new HashMap<Language, String> (); : } I would like to retrieve all Form records having a translation containing (!) « xxx ». The following

Apply “like” on blob field with Hibernate (Mysql)

寵の児 提交于 2019-12-25 07:29:56
问题 I have to build my query using an Array of Restrinction and I have to apply a like on a Blob field. If I do this, it works: Restrictions.like("DBFieldName", object.getFieldName()); Now, I need to add the % , but if I do something like: Restrictions.like("DBFieldName", "%" + object.getFieldName()); I get this error: java.lang.ClassCastException: java.lang.String cannot be cast to java.sql.Blob What should I do? Thank you 回答1: you cant compare a String value to blob through Criteria because