0

我是 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;
/
4

3 回答 3

3

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

set serveroutput on;

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

于 2013-03-24T19:40:15.267 回答
1
  1. 正如其他人所说,SQL*Plus 只会在您先从 DBMS_OUTPUT 获取输出SET SERVEROUT ON
  2. 您的代码只是在数据库上编译和存储一个数据库包;你实际上并没有运行它。要运行它,您将执行如下操作:

    BEGIN menu.show('something'); END;
    /
    
于 2013-03-26T07:20:57.850 回答
0

请阅读文档

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。

于 2013-03-25T09:58:30.737 回答