我有params的程序:
procedure GetReceipt(iPaymentID in number
,oReceipt out sys_refcursor
,oReceiptItems out sys_refcursor);
我尝试运行这个匿名块:
SET serveroutput on;
DECLARE
oReceipt sys_refcursor;
oReceiptItems sys_refcursor;
BEGIN
API.MOD.GetReceipt(4209735, oReceipt, oReceiptItems);
dbms_output.put_line('oReceipt: ' || oReceipt);
dbms_output.put_line('oReceiptItems: ' || oReceiptItems);
END;
我收到此错误:
Error report:
ORA-06550: Строка 6, столбец 24:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: Строка 6, столбец 3:
PL/SQL: Statement ignored
ORA-06550: Строка 7, столбец 24:
PLS-00306: wrong number or types of arguments in call to '||'
ORA-06550: Строка 7, столбец 3:
PL/SQL: Statement ignored
06550. 00000 - "line %s, column %s:\n%s"
*Cause: Usually a PL/SQL compilation error.
*Action:
如何调用此程序?我的错误在哪里?
答案 0 :(得分:3)
sys_refcursor
返回record set
,可能不只是一列。
因此,您不能将其作为带dbms_output.put_line
的经典字符串发送。在您的例程中应该存在此参数的一些列(子组件),例如oReceiptItems.col_a
或oReceiptItems.col_b
,以便您可以将这些列作为带dbms_output.put_line
的字符串发送。
答案 1 :(得分:2)
您可以使用绑定变量来存储游标,并使用PRINT
来打印游标:
VARIABLE receipt REFCURSOR;
VARIABLE receiptitems REFCURSOR;
BEGIN
API.MOD.GetReceipt(4209735, :receipt, :receiptitems);
END;
/
PRINT receipt;
PRINT receiptitems;
我的错误在哪里?
cursor是指向私有SQL区域的指定指针,该区域存储用于处理特定查询的信息。使用字符串将指向数据库内部的指针连接起来是没有意义的。
如果要在PL / SQL块中显示值,则需要遍历游标的每个记录并获取该记录的各个列值,然后使用DBMS_OUTPUT
显示它们:< / p>
SET serveroutput on;
DECLARE
oReceipt sys_refcursor;
oReceiptItems sys_refcursor;
col1 RECEIPT_TABLE.COL1%TYPE; -- Same data type as COL1 of the RECEIPT_TABLE table
col2 RECEIPT_TABLE.COL2%TYPE; -- Same data type as COL2 of the RECEIPT_TABLE table
col3 RECEIPT_TABLE.COL3%TYPE; -- Same data type as COL3 of the RECEIPT_TABLE table
rec RECEIPT_ITEMS_TABLE%ROWTYPE; -- Assumes the cursor is returning all the columns from
-- the RECEIPT_ITEMS_TABLE table
BEGIN
API.MOD.GetReceipt(4209735, oReceipt, oReceiptItems);
dbms_output.put_line('oReceipt:');
LOOP
FETCH oReceipt INTO col1, col2, col3; -- Store the values from the current record
EXIT WHEN oReceipt%NOTFOUND; -- Stop if the end of the cursor has been reached
DBMS_OUTPUT.PUT_LINE( col1 || ' ' || col2 || ' ' || col3 );
-- Output the values
END LOOP;
dbms_output.put_line('oReceiptItems:');
LOOP
FETCH oReceiptItems INTO rec; -- Fetch the current row into a record
EXIT WHEN oReceipt%NOTFOUND;
DBMS_OUTPUT.PUT_LINE( rec.colA || ' ' || rec.colB || ' ' || rec.colC );
END LOOP;
END;
/