Skip to content
Advertisement

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)

Advertisement

Answer

Concatenate the prefix/suffix with the bind variable:

SELECT * FROM table WHERE column like '%' || :bindvalue || '%'
User contributions licensed under: CC BY-SA
10 People found this is helpful
Advertisement