简体   繁体   English

为 PL SQL 打印 header 程序

[英]Printing header for PL SQL Procedure

I have the following SQL Procedure code:我有以下 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;
/

When ran, gives me: https://i.imgur.com/zEEKpya.png运行时,给我: https://i.imgur.com/zEEKpya.png

I'm trying to have this show: https://i.imgur.com/7fvAc6O.png我正在尝试这个节目: https://i.imgur.com/7fvAc6O.png

Any idea how to print the header out?知道如何打印 header 吗?

DBMS_OUTPUT.PUT_LINE seems limited DBMS_OUTPUT.PUT_LINE 似乎有限

Thanks in advance!提前致谢!

PS, I tried having a DBMS_OUTPUT.PUT_LINE before the loop but it errored out: PS,我尝试在循环之前有一个 DBMS_OUTPUT.PUT_LINE 但它出错了:

12/1 PLS-00103: Encountered the symbol "DBMS_OUTPUT" when expecting one of the following: loop The symbol "loop" was substituted for "DBMS_OUTPUT" to continue. 12/1 PLS-00103:在预期以下情况之一时遇到符号“DBMS_OUTPUT”:循环符号“循环”被替换为“DBMS_OUTPUT”以继续。

20/5 PLS-00103: Encountered the symbol "NUMOFSUPPLIER" when expecting one of the following: loop 20/5 PLS-00103:在预期以下情况之一时遇到符号“NUMOFSUPPLIER”:循环

Error when trying:尝试时出错:

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;
/

You cannot put the DBMS_OUTPUT.PUT_LINE in the middle of the loop's header.您不能将DBMS_OUTPUT.PUT_LINE放在循环 header 的中间。 You have to put it completely before the loop.你必须把它完全放在循环之前。

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

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM