2

I am using SQL Developer. When I want to bind value. Normally I use following syntax:

    SELECT * FROM table WHERE column = :bindvalue

but, I don't know how to do that in string. The following query does not work.

    SELECT * FROM table WHERE column like '%:bindvalue%'

Why do I need it? Because my program runs a query in python and assigns something to bind variable:

    curr.execute('''SELECT * FROM table WHERE column''' = :bindvalue, bindvalue=somevalue)
MT0
  • 143,790
  • 11
  • 59
  • 117
Mozgawa
  • 115
  • 9

1 Answers1

6

Concatenate the prefix/suffix with the bind variable:

SELECT * FROM table WHERE column like '%' || :bindvalue || '%'
MT0
  • 143,790
  • 11
  • 59
  • 117
  • In fact, it's so obvious that I'm ashamed. Thanks for the answer. – Mozgawa Nov 26 '19 at 12:58
  • Thanks for this, helped me today. Note for MySQL, you would need to use `CONCAT('%', :bindvalue, '%')` OR have the PIPES_AS_CONCAT SQL mode enabled. – Alex L Apr 13 '21 at 09:14