为 PL SQL 程序打印 header

Printing header for PL SQL Procedure

我有以下SQL程序代码:

create or replace procedure numOfSupplier(X IN NUMBER)IS
OUTPUT VARCHAR(500);

BEGIN 

    FOR supplerTable IN (SELECT R_NAME, N_NAME
    FROM SUPPLIER join NATION on S_NATIONKEY = N_NATIONKEY
    join REGION on N_REGIONKEY = R_REGIONKEY
    GROUP BY R_NAME, N_NAME
    HAVING COUNT (S_NATIONKEY) > X)

LOOP

DBMS_OUTPUT.PUT_LINE (supplerTable.R_NAME || supplerTable.N_NAME);

END LOOP;

END numOfSupplier;
/

当运行时,给我:https://i.imgur.com/zEEKpya.png

我想看这个节目:https://i.imgur.com/7fvAc6O.png

知道如何打印 header 吗?

DBMS_OUTPUT.PUT_LINE 似乎有限

提前致谢!

PS,我尝试在循环之前设置 DBMS_OUTPUT.PUT_LINE 但它出错了:

12/1 PLS-00103: 期待时遇到符号 "DBMS_OUTPUT" 以下之一: 环形 符号 "loop" 已替换为 "DBMS_OUTPUT" 以继续。

20/5 PLS-00103: 期待时遇到符号 "NUMOFSUPPLIER" 以下之一: 循环

尝试时出错:

OUTPUT VARCHAR(500);

BEGIN 

    FOR supplerTable IN (SELECT R_NAME, N_NAME
    FROM SUPPLIER join NATION on S_NATIONKEY = N_NATIONKEY
    join REGION on N_REGIONKEY = R_REGIONKEY
    GROUP BY R_NAME, N_NAME
    HAVING COUNT (S_NATIONKEY) > X)

DBMS_OUTPUT.PUT_LINE ('HELLO');

LOOP

DBMS_OUTPUT.PUT_LINE (supplerTable.R_NAME || supplerTable.N_NAME);

END LOOP;

END numOfSupplier;
/

您不能将 DBMS_OUTPUT.PUT_LINE 放在循环的 header 中间。你必须把它完全放在循环之前。

...
DBMS_OUTPUT.PUT_LINE ('<The header goes here>');

FOR supplerTable IN (...) LOOP
  DBMS_OUTPUT.PUT_LINE (supplerTable.R_NAME || supplerTable.N_NAME);
END LOOP;
...