gpt4 book ai didi

sql - 在 PL SQL 过程中使用 'execute immediate' 的问题

转载 作者:行者123 更新时间:2023-12-04 17:27:28 25 4
gpt4 key购买 nike

我在 PL SQL 过程中使用以下代码:

execute immediate 'select count(distinct item_type) into counter_variable
from items where ' || field_name || ' is not null'

这里,

counter_variable 在过程的声明部分声明
field_name 是 PL SQL 过程的 IN 参数,传递的值将是“items”表中的列名

我得到的错误是“无效的 SQL 语句”,我无法找出原因。有任何想法吗?

谢谢

最佳答案

into子句是 PL/SQL 并且在 SQL 语句中无效。
尝试这个:

execute immediate 'select count(distinct item_type) 
from items where ' || field_name || ' is not null' into counter_variable

关于sql - 在 PL SQL 过程中使用 'execute immediate' 的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6264591/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com