I can see a few issues off-hand.
- you are missing an equals sign when defining your variable;
- your substitution variable reference should not be in single quotes;
- you are repeating the
IN keyword;
- the column expression alias should also not be in single quotes.
DEFINE my_variable = IN ('term1', 'term2', 'term3')
SELECT
CASE WHEN my_field &my_variable THEN 1 ELSE 0 END AS new_field
FROM my_table
Running that with set verify on shows the final, valid, query it generates:
old:SELECT
CASE WHEN my_field &my_variable THEN 1 ELSE 0 END AS new_field
FROM my_table
new:SELECT
CASE WHEN my_field IN ('term1', 'term2', 'term3') THEN 1 ELSE 0 END AS new_field
FROM my_table
NEW_FIELD
----------
1
I have many terms that I am putting into the variable, and I am adding line breaks to help keep the code clean. However, when I do this, it causes the query to error.
If you want to split the define into multiple lines you can use the - continuation character, but in SQL Developer you need to actually make it a comment for it to work properly:
DEFINE my_variable = IN ( --
'term1', --
'term2', --
'term3')
SELECT
CASE WHEN my_field &my_variable THEN 1 ELSE 0 END AS new_field
FROM my_table
/
which set verify on shows as:
old:SELECT
CASE WHEN my_field &my_variable THEN 1 ELSE 0 END AS new_field
FROM my_table
new:SELECT
CASE WHEN my_field IN ( --
'term1', --
'term2', --
'term3') THEN 1 ELSE 0 END AS new_field
FROM my_table
NEW_FIELD
----------
1