Pl / SQL代码不提供任何输出

时间:2013-03-24 19:38:58

标签: oracle plsql

我是PL / SQL编码的初学者。 这是一个测试程序。

请告诉我没有输出的原因。

请指导我。

create or replace package menu as
procedure show(name varchar2);

end menu;
/

create or replace package body menu as
procedure show(name varchar2) AS
new_number number;
begin
select count(*) into  new_number from stock;

dbms_output.put_line('This is output.');

end;
end menu;
/

3 个答案:

答案 0 :(得分:3)

您需要将Oracle设置为手动输出到控制台:

set serveroutput on;

这应该是代码中的第一行。

答案 1 :(得分:1)

  1. 正如其他人所说,如果你第一次SET SERVEROUT ON,SQL * Plus只会从DBMS_OUTPUT获取输出。
  2. 您的代码只是编译并在数据库中存储数据库包;你实际上没有运行它。要运行它,你可以执行类似这样的事情:

    BEGIN menu.show('something'); END;
    /
    

答案 2 :(得分:0)

请阅读docs

Operational Notes

If you do not call GET_LINE, or if you do not display the messages on your screen in SQL*Plus, the buffered messages are ignored.

SQL*Plus calls GET_LINES after issuing a SQL statement or anonymous PL/SQL calls.

Typing SET SERVEROUTPUT ON in SQL*Plus has the effect of invoking

DBMS_OUTPUT.ENABLE (buffer_size => NULL);
with no limit on the output.

You should generally avoid having application code invoke either the DISABLE Procedure or ENABLE Procedure because this could subvert the attempt of an external tool like SQL*Plus to control whether or not to display output.

Note:
Messages sent using DBMS_OUTPUT are not actually sent until the sending subprogram or trigger completes. There is no mechanism to flush output during the execution of a procedure.
Exceptions

DBMS_OUTPUT subprograms raise the application error ORA-20000, and the output procedures can return the following errors:

Table 68-1 DBMS_OUTPUT Errors

Error Description
ORU-10027:     Buffer overflow
ORU-10028:     Line length overflow

Rules and Limits

The maximum line size is 32767 bytes.

The default buffer size is 20000 bytes. The minimum size is 2000 bytes and the maximum is unlimited.

因此SET SERVEROUTPUT ON仅适用于SQL * Plus。