当前位置:网站首页>Kingbasees plug-in DBMS of Jincang database_ OUTPUT

Kingbasees plug-in DBMS of Jincang database_ OUTPUT

2022-06-25 11:07:00 Thousands of sails pass by the side of the sunken boat_

Catalog

1. summary

2. Limit

3. Enable

4. Ban

5. DBMS_OUTPUT The system package supports entering information into the buffer

6. DBMS_OUTPUT The system package supports getting information from the buffer

7. DBMS_OUTPUT The system package supports the client to display buffer information



1. summary


DBMS_OUTPUT System packages can provide the ability to write text lines to a buffer 、 Functions for later extraction and display . Mainly used for debugging PL/SQL Program , Or in Ksql Display information and reports in client commands , For example, we can write a simple anonymous pl/sql Block , The block can use this package to display some information for some purpose .
DBMS_OUTPUT The system package does not support PG Pattern .

 

2. Limit


DBMS_OUTPUT Row and buffer size limits :

  • The maximum row size is 32767 byte .
  • The default buffer size is 20000 byte . The minimum is 2000 byte , The greatest is infinite .



3. Enable


Grammar format :

DBMS_OUTPUT.ENABLE(buffer_size IN INTEGER DEFAULT 20000);

Function description :

This procedure allows you to call PUT、PUT_LINE、NEW_LINE、GET_LINE and GET_LINES Etc .

Parameter description :

buffer_size: The maximum buffer size is 1000000 byte , The minimum is 2000 byte , The default is 20000 byte . take buffer_size Set to null, There will be no limit on the buffer size .

Instructions :

  • If it's not activated DBMS_OUTPUT package , Calls to these procedures will be ignored .
  • If there are multiple calls to enable , that buffer_size The last specified value .
  • When set serveroutput on When it is turned on, it is not necessary to call enable and disable The process .
  • The cache setting size range is 2000 to 1000000, If buffer_size The value is less than 2000, Then for 2000; If buffer_size The value of exceeds 1000000, Then for 1000000; If the data size of the input buffer exceeds the maximum value set by the buffer , Will report an error directly .

Example :

call dbms_output.enable();
call dbms_output.enable(NULL);
call dbms_output.enable(3000);


4. Ban


Grammar format :

DBMS_OUTPUT.DISABLE();

Function description :

This procedure disables access to PUT、PUT_LINE、NEW_LINE、GET_LINE and GET_LINES And so on , And clear the buffer .

Instructions :

  • If it's time to DBMS_OUTPUT Packages are disabled , So all of its subroutines (subprogram) Will be ignored . This allows users to design applications , Enable these subroutines only if the client program can process this information .
  • If set serveroutput off Time to call disable The process , Next time you call another procedure , Must call enable The process .



5. DBMS_OUTPUT The system package supports entering information into the buffer


5.1. Append content to the buffer
Grammar format :

DBMS_OUTPUT.PUT(item IN VARCHAR2);

Function description :

This process is used to append part of the content to Buffer The last line in .

Instructions :

  • When adding content, you can use put Process input , If you want to input in a whole line, you'd better use put_line The process .
  • If the length of a single line exceeds the limit, an error will be reported , Or if the input data exceeds the set value of the cache, an error will be reported .
  • Pay attention to calling PUT or PUT_LINE Of PL/SQL Before the end of the program unit , Yes PUT or PUT_LINE The specified content will not be output .
  • When calling PUT_LINE Line breaks will be automatically added to the procedure , If you use PUT To construct the bank , Then it must be used manually NEW_LINE Procedure to add line breaks .GET_LINE and GET_LINES The procedure does not return a line that does not end with a newline character .

Example :

set serveroutput on
\set SQLTERM /
begin
    dbms_output.put('test1');
    dbms_output.new_line();
    dbms_output.put('test2');
end;
/


5.2. Append single line information to the buffer
Grammar format :

DBMS_OUTPUT.PUT_LINE(item IN VARCHAR2);

Function description :

This stored procedure is used to send a message to Buffer A new line of information is added to the .

Instructions :

  • If the input data exceeds the set value of the buffer, an error will be reported .
  • GET_LINE and GET_LINES Do not return lines that are not terminated with a newline character .

Example :

set serverout on
call dbms_output.put_line('hi' || chr(10) || 'hello'||chr(10) || '
world');
/

5.3. Append a new row to the buffer
Grammar format :

DBMS_OUTPUT.NEW_LINE();

Function description :

The stored procedure adds a line break to the buffer , Generate a new line .

Instructions :

  • A new row is generated every time it is called .

Example :

set serverout on
begin
    dbms_output.put('test1');
    dbms_output.new_line();
    dbms_output.put('test2');
    dbms_output.new_line();
    dbms_output.new_line();
    dbms_output.put_line('test3');
end;
/


6. DBMS_OUTPUT The system package supports getting information from the buffer


6.1. Get the first line of information
Grammar format :

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

Function description :

The process starts from buffer Get single line information in , The information added first is obtained first , After acquisition buffer This information in will be deleted .
Parameter and return value instructions :
  • line: Will get buffer A line of information in , But does not include the last line break .
  • status: If the call succeeds, it returns 0, If the call fails, it returns 1.

Instructions :

call GET_LINE or GET_LINES After successfully obtaining the content , In the next call PUT, PUT_LINE or NEW_LINE Any cache that is not fetched before the process will be discarded , To avoid misunderstanding .

Example :

set serverout on
\set SQLTERM /
declare
    line varchar2(120);
    status integer;
begin
    dbms_output.put('hello');
    dbms_output.put_line('world');
    dbms_output.get_line(line, status);
    dbms_output.put_line(line || status);
end;
/


6.2. Get multi line information
Grammar format :

PROCEDURE get_lines(lines OUT CHARARR, numlines IN OUT integer);
PROCEDURE get_lines(lines OUT DBMSOUTPUT_LINESARRAY, numlines IN OUT
integer);

Function description :

This stored procedure is used to retrieve data from Buffer Get a multi row array from , After acquisition buffer This information in will be deleted .
Description of parameters and return values :
  • CHARARR( In package type ):TYPE CHARARR IS TABLE OF VARCHAR2(32767) INDEX BY INT;
  • DBMSOUTPUT_LINESARRAY( Out of package type ):TYPE DBMSOUTPUT_LINESARRAY IS VARRAY(2147483647) OF VARCHAR2(32767);
  • lines: Returns the row array of buffered information . The maximum length of each row in the array is 32767 byte .
  • numlines: When the number of rows in the cache is greater than or equal to the number of rows retrieved , Returns the number of rows retrieved ; When the number of rows in the cache is less than the number of rows retrieved , Returns the number of rows in the cache .

Instructions :

  • After getting the information , If the input procedure is called next time , Any rows that are not retrieved will be discarded , To avoid confusion with the next message .
  • CHARARR type numlines Parameters : When no parameter is specified or this parameter is less than or equal to 0, Don't get content , And back to numlines by 0; When this parameter is greater than 0, If the number of rows in the cache is greater than or equal to the number of rows retrieved , Returns the number of rows retrieved ; If the number of rows in the cache is less than the number of rows retrieved , Returns the number of rows in the cache .
  • DBMSOUTPUT_LINESARRAY type numlines Parameters : When no parameter is specified , Get all contents by default , And back to numlines To get the number of rows ; When this parameter is less than 0, Will be an error ; When the parameter is greater than or equal to 0 when , If the number of rows in the cache is greater than or equal to the number of rows retrieved , Returns the number of rows retrieved , When the number of rows in the cache is less than the number of rows retrieved , Returns the number of rows in the cache .

Example :

set serverout on
DECLARE
    v_data  dbms_output.CHARARR;
    numlines integer := 2;
BEGIN
    dbms_output.put_line('TEST 1');
    dbms_output.put_line('TEST 2');
    dbms_output.put_line('TEST 3');
    dbms_output.get_lines(v_data, numlines);
    dbms_output.put_line(v_data(1));
    dbms_output.put_line(v_data(2));
end;
/
DECLARE
    v_data  DBMSOUTPUT_LINESARRAY;
    numlines integer := 2;
BEGIN
    dbms_output.put_line('TEST 1');
    dbms_output.put_line('TEST 2');
    dbms_output.get_lines(v_data, numlines);
    dbms_output.put_line(numlines);
    dbms_output.put_line(v_data(1));
    dbms_output.put_line(v_data(2));
end;
/


7. DBMS_OUTPUT The system package supports the client to display buffer information


7.1. The client command starts the output function
Grammar format :

set serverout[put] on[;]

Function description :

  • Enable DBMS_OUTPUT System package functions .
  • The cache size is set to unlimited .
  • Can replace enable The process , That is, you don't need enable The process .
  • Client output cache messages .

Instructions :

set serverout[put] Follow ‘on’ or ‘on;’, When you enter an unrelated command, you will be prompted with a command error .

Example :

set serverout on
create or replace procedure protest_A_1 is
begin
  dbms_output.put_line('....test1');
  dbms_output.put_line('....test2');
end;
/
declare
  v_status integer := 0;
  v_data varchar2(100);
begin
  protest_A_1();
  dbms_output.put_line('test3');
  dbms_output.get_line(v_data, v_status);
  dbms_output.put_line('v_data: ' ||v_data || 'v_status: ' ||v_status);
  dbms_output.put_line('test4');
end;
/


7.2. The client command disables the output function
Grammar format :

set serverout[put] off[;]

Function description :

  • Ban DBMS_OUTPUT System package functions .
  • Clear cache .
  • Can replace disable The process , That is, you don't need disable The process .

Instructions :

set serverout[put] Follow ‘off’ or ‘off;’, When you enter an unrelated command, you will be prompted with a command error .

Example :

set serverout off
call dbms_output.put_line('hi' || chr(10) || 'hello'||chr(10) || '
world');
/


 

原网站

版权声明
本文为[Thousands of sails pass by the side of the sunken boat_]所创,转载请带上原文链接,感谢
https://yzsam.com/2022/176/202206251044550150.html