我们有一个名为“Get()”的现有 PL SQL 过程,当提供 order_no_ 和 sequence_no_ 时,它返回一个名为“CURSOR_TYPE”的命名 REF CURSOR 类型。我需要对此方法进行“重载”,程序员只需传入 order_no_(无 sequence_no_),它会重复调用该方法并将所有 sequence_no_ 值的所有记录收集到单个返回“CURSOR_TYPE”REF CURSOR 中。以下是我为尝试完成此操作而写的内容,并尝试按照此处显示的示例进行操作。
PROCEDURE Get(order_no_ IN VARCHAR2, results_cursor OUT CURSOR_TYPE)
AS
--Declare a "nested table type" table
TYPE CoC_RowType IS TABLE OF customer_order_charge_cfv%ROWTYPE;
CoC_RowTable CoC_RowType := CoC_RowType();
CURSOR c1 IS
SELECT coc.SEQUENCE_NO
FROM customer_order_charge_cfv coc
WHERE coc.ORDER_NO = order_no_;
BEGIN
FOR i in c1 LOOP
CoC_RowTable.extend();
Get(order_no_, i.sequence_no, results_cursor);
FETCH results_cursor INTO CoC_RowTable(CoC_RowTable.count);
END LOOP;
OPEN results_cursor FOR SELECT * FROM TABLE(CoC_RowTable);
END Get;
但是,当我尝试将此代码编译到我的包中时,我收到以下错误:
Compilation errors for PACKAGE BODY GLOB1APP.GFS_CUSTOMER_ORDER_CHARGE_CFP
Error: PLS-00382: expression is of wrong type
Line: 81
Text: OPEN results_cursor FOR SELECT * FROM TABLE(CoC_RowTable);
Error: PL/SQL: ORA-22905: cannot access rows from a non-nested table item
Line: 81
Text: OPEN results_cursor FOR SELECT * FROM TABLE(CoC_RowTable);
Error: PL/SQL: SQL Statement ignored
Line: 81
Text: OPEN results_cursor FOR SELECT * FROM TABLE(CoC_RowTable);
它似乎在这一行出错:
OPEN results_cursor FOR SELECT * FROM TABLE(CoC_RowTable);
我究竟做错了什么?我怎样才能实现我的目标?这完全是实现这一目标的错误途径吗?