Reputation: 7029
I am using the following code in a PL SQL procedure:
execute immediate 'select count(distinct item_type) into counter_variable
from items where ' || field_name || ' is not null'
Here,
counter_variable is declared in the declaration section of the procedure field_name is the IN parameter to the PL SQL procedure and the values passed will be column names from the 'items' table
The error that I get is 'Invalid SQL Statement' and I am not able to figure out the reason. Any ideas?
Thanks
Upvotes: 5
Views: 3306
Reputation: 33283
The into
clause is PL/SQL and not valid in an SQL statement.
Try this:
execute immediate 'select count(distinct item_type)
from items where ' || field_name || ' is not null' into counter_variable
Upvotes: 10