I am using the following code in a PL SQL procedure:
我在PL SQL过程中使用以下代码:
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
counter_variable在过程的声明部分声明field_name是PL SQL过程的IN参数,传递的值将是'items'表中的列名
The error that I get is 'Invalid SQL Statement' and I am not able to figure out the reason. Any ideas?
我得到的错误是“无效的SQL语句”,我无法弄清楚原因。有任何想法吗?
Thanks
谢谢
1 个解决方案
#1
10
The into
clause is PL/SQL and not valid in an SQL statement. Try this:
into子句是PL / SQL,在SQL语句中无效。尝试这个:
execute immediate 'select count(distinct item_type)
from items where ' || field_name || ' is not null' into counter_variable
#1
10
The into
clause is PL/SQL and not valid in an SQL statement. Try this:
into子句是PL / SQL,在SQL语句中无效。尝试这个:
execute immediate 'select count(distinct item_type)
from items where ' || field_name || ' is not null' into counter_variable