Search code examples
oracle-databasesql-like

Oracle: missing right parenthesis


I have a query:

SELECT (column LIKE '%string%') AS bool FROM table

It returns:

"missing right parenthesis"

Why?


Solution

  • Because of the LIKE operator, we can't use the DECODE function. I guess the following, as ugly as it is, matches what you're looking for:

    SELECT
        login,
        CASE 
            WHEN login LIKE 'admin' THEN 1
            ELSE 0
        END
    FROM users;
    

    or, with boolean like values:

    SELECT
        login,
        CASE 
            WHEN login LIKE 'admin' THEN 'TRUE'
            ELSE 'FALSE'
        END
    FROM users;
    

    If you are using the LIKE operator, you would like to use some % wildcards in the 'admin' string, otherwise a simple equality is enough.

    Fiddle

    Documentation