如何dbms_output记录变量

How to dbms_output record variable

set serveroutput on;
DECLARE
  PI_STARTDATE DATE;
  PO_STATUS NUMBER;
  PO_HEADER VARCHAR2(200);
  PO_LABEL VARCHAR2(200);
  PO_RECORD SYS_REFCURSOR;
  PO_NEXTINCSTARTDATE DATE;
BEGIN
  PI_STARTDATE := to_date('2020-05-01','yyyy-MM-dd');
  PCK_FAB_REPORTS.PRC_MONTHLY_WRTOFF_REPORT(
    PI_STARTDATE => PI_STARTDATE,
    PO_STATUS => PO_STATUS,
    PO_HEADER => PO_HEADER,
    PO_LABEL => PO_LABEL,
    PO_RECORD => PO_RECORD,
    PO_NEXTINCSTARTDATE => PO_NEXTINCSTARTDATE);
DBMS_OUTPUT.PUT_LINE('PO_STATUS = ' || PO_STATUS);
DBMS_OUTPUT.PUT_LINE('PO_HEADER = ' || PO_HEADER);
DBMS_OUTPUT.PUT_LINE('PO_LABEL = ' || PO_LABEL);
DBMS_OUTPUT.PUT_LINE('PO_NEXTINCSTARTDATE = ' || PO_NEXTINCSTARTDATE);
END;

我想对过程进行单元测试并且还想显示引用光标变量。如何使用 dbms 显示参考光标?

这是一个基于 Scott 的 EMP 的示例 table:

SQL> set serveroutput on
SQL>
SQL> declare
  2    l_ename   emp.ename%type;
  3    l_job     emp.job%type;
  4    l_rc      sys_refcursor;
  5  begin
  6    open l_rc for select ename, job from emp
  7                  where deptno = 10;
  8
  9    loop
 10      fetch l_rc into l_ename, l_job;
 11      exit when l_rc%notfound;
 12
 13      dbms_output.put_line(l_ename ||' '|| l_job);
 14    end loop;
 15    close l_rc;
 16  end;
 17  /
CLARK MANAGER
KING PRESIDENT
MILLER CLERK

PL/SQL procedure successfully completed.

SQL>

因此:您必须获取 refcursor 到变量中,然后显示这些变量的内容。