Skip to content

Tarik Billa

  • Web Development
    • html
    • vue.js
    • laravel
    • css
    • javascript
    • jquery
    • node.js
    • php
    • asp.net
  • Programming
    • python
    • java
    • c
    • c++
    • c#
  • git
  • android

sql-like

Using LIKE in an Oracle IN clause

April 8, 2024 by Tarik

What would be useful here would be a LIKE ANY predicate as is available in PostgreSQL SELECT * FROM tbl WHERE my_col LIKE ANY (ARRAY[‘%val1%’, ‘%val2%’, ‘%val3%’, …]) Unfortunately, that syntax is not available in Oracle. You can expand the quantified comparison predicate using OR, however: SELECT * FROM tbl WHERE my_col LIKE ‘%val1%’ OR … Read more

Categories sql Tags oracle, sql, sql-like Leave a comment

Regular expression to match start of filename and filename extension

April 8, 2024 by Tarik

For a regular expression, you would use: re.match(r’Run.*\.py$’) A quick explanation: . means match any character. * means match any repetition of the previous character (hence .* means any sequence of chars) \ is an escape to escape the explicit dot $ indicates “end of the string”, so we don’t match “Run_foo.py.txt” However, for this … Read more

Categories python Tags python, regex, sql, sql-like Leave a comment

Should LIKE ‘searchstr%’ use an index?

January 6, 2024 by Tarik

An index cannot safely be used in this case. A naive implementation would transform this: … WHERE word LIKE ‘search_string%’ into … WHERE word >= ‘search_string’ AND word < ‘search_strinh’ by incrementing the last character of the search string. The greater-than and less-than operators can use an index, where LIKE cannot. Unfortunately, that won’t work … Read more

Categories sql Tags cocoa, query-optimization, sql, sql-like, sqlite Leave a comment

SWITCH with LIKE inside SELECT query in MySQL

December 23, 2023 by Tarik

Mysql supports two variants of case, the one you use in query 2 is less flexible but supports only equality on a single variable. The other version specifies no variable after case and then conditions need not be only equality: select id_tag, case when tag LIKE “%class%” then “class” when tag LIKE “%new%” then “new” … Read more

Categories sql Tags case, mysql, sql, sql-like, switch-statement Leave a comment

How can you find a literal percent sign (%) in PostgreSQL using a LIKE query?

November 29, 2023 by Tarik

You can try like this: SELECT * FROM my_table WHERE my_column LIKE ‘%\%%’ ESCAPE ‘\’; Format <like predicate> ::= <match value> [ NOT ] LIKE <pattern> [ ESCAPE <escape character> ] <match value> ::= <character value expression> <pattern> ::= <character value expression> <escape character> ::= <character value expression>

Categories postgresql Tags postgresql, sql-like Leave a comment

SQL Server: use CASE with LIKE

November 29, 2023 by Tarik

This is the syntax you need: CASE WHEN countries LIKE ‘%’+@selCountry+’%’ THEN ‘national’ ELSE ‘regional’ END Although, as per your original problem, I’d solve it differently, splitting the content of @selcountry int a table form and joining to it.

Categories sql Tags case, sql, sql-like, sql-server, stored-procedures Leave a comment

Mysql: Order by like?

September 17, 2023 by Tarik

order by case when name LIKE “%John%” then 1 when name LIKE “%Doe%” then 2 else 3 end

Categories mysql Tags mysql, sql, sql-like, sql-order-by Leave a comment

How do I perform a case-sensitive search using LIKE?

September 6, 2023 by Tarik

Try using COLLATE Latin1_General_BIN rather than COLLATE Latin1_General_CS_AS

Categories sql-server-2008 Tags collate, pattern-matching, sql-like, sql-server-2008 Leave a comment

Cannot use a LIKE query in a JDBC PreparedStatement?

September 6, 2023 by Tarik

First, the PreparedStatement placeholders (those ? things) are for column values only, not for table names, column names, SQL functions/clauses, etcetera. Better use String#format() instead. Second, you should not quote the placeholders like ‘?’, it would only malform the final query. The PreparedStatement setters already do the quoting (and escaping) job for you. Here’s the … Read more

Categories java Tags java, jdbc, oracle, sql-like Leave a comment

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

August 21, 2023 by Tarik

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 can be better and lead to a more appropriate plan when the square bracket syntax is used. The response to this Connect Item states We … Read more

Categories sql-server Tags sql-like, sql-server, tsql Leave a comment
Older posts
Page1 Page2 … Page7 Next →

Tarik Billa

Software Engineer
tarikbilla@gmail.com
+8801884414000
  • Reuse a hash in YAMLApril 17, 2024
  • Dockerfile: how to redirect the output of a RUN command to a variable?April 16, 2024
  • How to cd to a directory with spaces in the directory name?April 16, 2024
  • Maximum MIME type length when storing the type in a databaseApril 16, 2024
  • What is the difference between Unit, Integration, Regression and Acceptance Testing?April 16, 2024
© 2026 Tarik Billa