日期:2014-05-17 浏览次数:20866 次
create or replace package dbms_output as -- DE-HEAD <- tell SED where to cut when generating fixed package ------------ -- OVERVIEW -- -- These procedures accumulate information in a buffer (via "put" and -- "put_line") so that it can be retrieved out later (via "get_line" or -- "get_lines"). If this package is disabled then all -- calls to this package are simply ignored. This way, these routines -- are only active when the client is one that is able to deal with the -- information. This is good for debugging, or SP's that want to want -- to display messages or reports to sql*dba or plus (like 'describing -- procedures', etc.). The default buffer size is 20000 bytes. The -- minimum is 2000 and the maximum is 1,000,000. ----------- -- EXAMPLE -- -- A trigger might want to print out some debugging information. To do -- do this the trigger would do -- dbms_output.put_line('I got here:'||:new.col||' is the new value'); -- If the client had enabled the dbms_output package then this put_line -- would be buffered and the client could, after executing the statement -- (presumably some insert, delete or update that caused the trigger to -- fire) execute -- begin dbms_output.get_line(:buffer, :status); end; -- to get the line of information back. It could then display the -- buffer on the screen. The client would repeat calls to get_line -- until status came back as non-zero. For better performance, the -- client would use calls to get_lines which can return an array of -- lines. -- -- SQL*DBA and SQL*PLUS, for instance, implement a 'SET SERVEROUTPUT -- ON' command so that they know whether to make calls to get_line(s) -- after issuing insert, update, delete or anonymous PL/SQL calls -- (these are the only ones that can cause triggers or stored procedures -- to be executed). ------------ -- SECURITY -- -- At the end of this script, a public synonym (dbms_output) is created -- and execute permission on this package is granted to public. ---------------------------- -- PROCEDURES AND FUNCTIONS -- procedure enable (buffer_size in integer default 20000); pragma restrict_references(enable,WNDS,RNDS); -- Enable calls to put, put_line, new_line, get_line and get_lines. -- Calls to these procedures are noops if the package has -- not been enabled. Set default amount of information to buffer. -- Cleanup data buffered from any dead sessions. Multiple calls to -- enable are allowed. -- Input parameters: -- buffer_size -- Amount of information, in bytes, to buffer. Varchar2, number and -- date items are stored in their internal representation. The -- information is stored in the SGA. An error is raised if the -- buffer size is exceeded. If there are multiple calls to enable, -- then the buffer_size is generally the largest of the values -- specified, and will always be >= than the smallest value -- specified. Currently a more accurate determination is not -- possible. The maximum size is 1,000,000, the minimum is 2000. procedure disable; pragma restrict_references(disable,WNDS,RNDS); -- Disable calls to put, put_line, new_line, get_line and get_lines. -- Also purge the buffer of any remaining information. procedure put(a varchar2); pragma restrict