Search code examples
sqloracleoracle12cbind-variables

How to bind variable in string in SQL query?


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)

Solution

  • Concatenate the prefix/suffix with the bind variable:

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