如何输出dbms\u记录变量

pdtvr36n  于 2021-08-13  发布在  Java
关注(0)|答案(1)|浏览(355)
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;

我想对这个过程进行单元测试,还想显示ref cursor变量。如何使用dbms显示ref游标?

1aaf6o9v

1aaf6o9v1#

下面是一个基于scott的emp表的示例:

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提取到变量中,然后显示这些变量的内容。

相关问题