您的第二个存储过程的代码片段:
FOR player IN rows LOOP
currentCount := maxCount;
DBMS_OUTPUT.PUT(player.FIRSTNAME || ' ' || player.LASTNAME || ':' || player.points || ' ');
--DBMS_OUTPUT.NEW_LINE();
END LOOP;
如果您希望结果输出显示为单行,您应该移到 DBMS_OUTPUT.NEW_LINE()
循环之外(循环之后)。所以你的代码看起来像:
FOR player IN rows LOOP
currentCount := maxCount;
DBMS_OUTPUT.PUT(player.FIRSTNAME || ' ' || player.LASTNAME || ':' || player.points || ' ');
END LOOP;
DBMS_OUTPUT.NEW_LINE();
在您模拟过程之后保持DBMS_OUTPUT.NEW_LINE();
在循环内。DBMS_OUTPUT.PUT
DBMS_OUTPUT.PUT_LINE
SQL> create or replace procedure output1
2 is
3 l_str varchar2(100);
4 l_status number;
5 begin
6 for i in 1..7
7 loop
8 dbms_output.put('Text_' || To_char(i));
9 dbms_output.new_line;
10 end loop;
11 end;
12 /
Procedure created
SQL>
SQL> create or replace procedure output2
2 is
3 l_str varchar2(100);
4 l_status number;
5 begin
6 for i in 1..7
7 loop
8 dbms_output.put('Text_' || To_char(i));
9 end loop;
10 dbms_output.new_line;
11 end;
12 /
Procedure created
SQL> exec output1;
Text_1
Text_2
Text_3
Text_4
Text_5
Text_6
Text_7
PL/SQL procedure successfully completed
SQL> exec output2;
Text_1Text_2Text_3Text_4Text_5Text_6Text_7
PL/SQL procedure successfully completed
在您的代码中:
SET serveroutput ON size 32000;
REM Change output file name TO proj3-NetID.OUT!
SPOOL proj3-hgeorge3.OUT;
exec DBMS_OUTPUT.enable('100000000');
如果serveroutput
使用选项(设置为 ON),则不需要调用 DBMS_OUTPUT.enable
过程。如果它碰巧被调用,DBMS_OUTPUT.enable
那么数值数据类型的值应该作为参数而不是字符串传递。是的,会有数据类型的隐式转换,但最好避免它。缓冲区的最大大小为 100 万。