[英]Function Oracle PL SQL bulk collect error PLS-00382: expression is of wrong type
I have this function:我有这个 function:
CREATE OR REPLACE TYPE products_type AS OBJECT
(
products VARCHAR2 (50),
price VARCHAR2 (50)
);
CREATE OR REPLACE TYPE results_type AS TABLE OF products_type;
create or replace get_sum ( l_products in varchar2(50)
RETURN results_type
IS
l_result results_type;
begin
SELECT distinct products, count(price)
BULK COLLECT INTO l_result
FROM products;
RETURN l_result;
END;
/
DECLARE
l_result varchar2(50) := '0';
BEGIN
l_result := get_sum ('apple')
DBMS_OUTPUT.PUT_LINE('Price total ' || l_result);
END;
I have this table and I want to know what the sum of a product is.我有这张表,我想知道乘积的总和是多少。 I try to learn how a function works when I want to display more than one column.
当我想显示多列时,我尝试了解 function 是如何工作的。 I found on the inte.net related to bulk collect and I tried to do so, but I encounter this error:
我在 inte.net 上找到了与 bulk collect 相关的内容,我尝试这样做,但是我遇到了这个错误:
PLS-00382: expression is of wrong type What am I doing wrong?
PLS-00382:表达式类型错误我做错了什么?
The problem is that in your function GET_SUM
, you are returning l_result which is of type results_type
.问题是在您的 function
GET_SUM
中,您返回的是 results_type 类型的results_type
。 In your anonymous block, you are calling GET_SUM
and attempting to assign it to a VARCHAR2(50)
variable.在您的匿名块中,您正在调用
GET_SUM
并试图将其分配给VARCHAR2(50)
变量。 The variable you are trying to assign the value to needs to match the return type of the function.您尝试为其赋值的变量需要匹配 function 的返回类型。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.