📜  PL / SQL-DBMS输出

📅  最后修改于: 2020-11-26 06:04:01             🧑  作者: Mango


在本章中,我们将讨论PL / SQL中的DBMS输出。 DBMS_OUTPUT是一个内置程序包,使您可以显示输出,调试信息并从PL / SQL块,子程序,程序包和触发器发送消息。我们已经在整个教程中使用了此软件包。

让我们看一个小的代码片段,它将显示数据库中的所有用户表。尝试在数据库中列出所有表名-

BEGIN 
   dbms_output.put_line  (user || ' Tables in the database:'); 
   FOR t IN (SELECT table_name FROM user_tables) 
   LOOP 
      dbms_output.put_line(t.table_name); 
   END LOOP; 
END; 
/ 

DBMS_OUTPUT子程序

DBMS_OUTPUT软件包具有以下子程序-

S.No Subprogram & Purpose
1

DBMS_OUTPUT.DISABLE;

Disables message output.

2

DBMS_OUTPUT.ENABLE(buffer_size IN INTEGER DEFAULT 20000);

Enables message output. A NULL value of buffer_size represents unlimited buffer size.

3

DBMS_OUTPUT.GET_LINE (line OUT VARCHAR2, status OUT INTEGER);

Retrieves a single line of buffered information.

4

DBMS_OUTPUT.GET_LINES (lines OUT CHARARR, numlines IN OUT INTEGER);

Retrieves an array of lines from the buffer.

5

DBMS_OUTPUT.NEW_LINE;

Puts an end-of-line marker.

6

DBMS_OUTPUT.PUT(item IN VARCHAR2);

Places a partial line in the buffer.

7

DBMS_OUTPUT.PUT_LINE(item IN VARCHAR2);

Places a line in the buffer.

DECLARE 
   lines dbms_output.chararr; 
   num_lines number; 
BEGIN 
   -- enable the buffer with default size 20000 
   dbms_output.enable; 
   
   dbms_output.put_line('Hello Reader!'); 
   dbms_output.put_line('Hope you have enjoyed the tutorials!'); 
   dbms_output.put_line('Have a great time exploring pl/sql!'); 
  
   num_lines := 3; 
  
   dbms_output.get_lines(lines, num_lines); 
  
   FOR i IN 1..num_lines LOOP 
      dbms_output.put_line(lines(i)); 
   END LOOP; 
END; 
/  

当以上代码在SQL提示符下执行时,将产生以下结果-

Hello Reader! 
Hope you have enjoyed the tutorials! 
Have a great time exploring pl/sql!  

PL/SQL procedure successfully completed.