2013-03-24 48 views
0

我是PL/SQL編碼的初學者。 這是一個測試程序。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; 
/
+0

SELECT COUNT(*)到從股票NEW_NAME; - 進入new_number並設置服務器輸出 – ajmalmhd04 2013-03-25 07:53:37

回答

3

您需要的Oracle設置爲輸出線,以手動控制檯:

set serveroutput on; 

這應該是你的第一行代碼。

+0

非常感謝你。 :) 我會期待發布更多的問題..:D – 2013-03-26 08:51:19

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. 

所以設置SERVEROUTPUT ON僅適用於在SQL * Plus。

1
  1. 正如其他人所說,如果您第一個SET SERVEROUT ON,SQL * Plus將只會從DBMS_OUTPUT獲得輸出。
  2. 您的代碼僅編譯數據庫包並將其存儲在數據庫中;你實際上並沒有運行它。要運行它,你會執行這樣的事情:

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