https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12040.htm
SET SERVEROUT[PUT] {ON | OFF} [SIZE {n | UNL[IMITED]}] [FOR[MAT] {WRA[PPED] | WOR[D_WRAPPED] | TRU[NCATED]}]
Controls whether to display output (that is, DBMS_OUTPUT.PUT_LINE) of stored procedures or PL/SQL blocks in SQL*Plus. The DBMS_OUTPUT line length limit is 32767 bytes.
OFF suppresses the output of DBMS_OUTPUT.PUT_LINE. ON displays the output.
ON uses the SIZE and FORMAT of the previous SET SERVEROUTPUT ON SIZE n FORMAT f, or uses default values if no SET SERVEROUTPUT command was previously issued in the current connection.
SIZE sets the number of bytes of the output that can be buffered within the Oracle Database server. The default is UNLIMITED. n cannot be less than 2000 or greater than 1,000,000. In iSQL*Plus you can enter the word UNLIMITED in the Size field of the Script Formatting Preferences screen.
Resources are not pre-allocated when SERVEROUTPUT is set. As there is no performance penalty, use UNLIMITED unless you want to conserve physical memory.
Every server output line begins on a new output line.
When WRAPPED is enabled SQL*Plus wraps the server output within the line size specified by SET LINESIZE, beginning new lines when required.
When WORD_WRAPPED is enabled, each line of server output is wrapped within the line size specified by SET LINESIZE. Lines are broken on word boundaries. SQL*Plus left justifies each line, skipping all leading whitespace.
When TRUNCATED is enabled, each line of server output is truncated to the line size specified by SET LINESIZE.
For detailed information about using UTL_FILE and associated utilities, see the Oracle Database PL/SQL Packages and Types Reference .
For more information on DBMS_OUTPUT.PUT_LINE, see your Oracle Database Application Developer's Guide - Fundamentals.
Example
To enable text display in a PL/SQL block using DBMS_OUTPUT.PUT_LINE, enter
SET SERVEROUTPUT ON
The following example shows what happens when you execute an anonymous procedure with SET SERVEROUTPUT ON:
BEGIN
DBMS_OUTPUT.PUT_LINE('Task is complete');
END;
/
The following example shows what happens when you create a trigger with SET SERVEROUTPUT ON:
CREATE TABLE SERVER_TAB (Letter CHAR);
CREATE TRIGGER SERVER_TRIG BEFORE INSERT OR UPDATE -
OR DELETE
ON SERVER_TAB
BEGIN
DBMS_OUTPUT.PUT_LINE('Task is complete.');
END;
/
INSERT INTO SERVER_TAB VALUES ('M');
DROP TABLE SERVER_TAB;
/* Remove SERVER_TAB from database */
To set the output to WORD_WRAPPED, enter
SET SERVEROUTPUT ON FORMAT WORD_WRAPPED
SET LINESIZE 20
BEGIN
DBMS_OUTPUT.PUT_LINE('If there is nothing left to do');
DBMS_OUTPUT.PUT_LINE('shall we continue with plan B?');
END;
/
To set the output to TRUNCATED, enter
SET SERVEROUTPUT ON FORMAT TRUNCATED
SET LINESIZE 20
BEGIN
DBMS_OUTPUT.PUT_LINE('If there is nothing left to do');
DBMS_OUTPUT.PUT_LINE('shall we continue with plan B?');
END;
/
SQL Developer로 프로시져를 사용하면서 로그를 확인하려면 SET시스템변수(SET System Variable)를 적용하고
DBMS_OUTPUT.PUT_LINE()을 사용한다.
SET시스템 변수(SET System Variable)
저장 프로시져의 DBMS_OUTPUT.PUT_LINE으로 표시하며, DBMS_OUTPUT라인의 길이는 32767byte이다
-- set시스템변수 적용하기 , 먼저 실행한다.
SET SERVEROUTPUT ON
-- 스크립트 출력(Script Output) 아래쪽 툴바 오른쪽에 메시지를 보여준다. - 스크립트 출력창 아님
Script Output>
작업이 완료되었습니다.(Task completed) -- 시스템변수 적용완료
-- 선언(필수)
DECLARE
v_num NUMBER := 0;
--시작(필수)
BEGIN
DBMS_OUTPUT.PUT_LINE('v_num'=||v_num);
--예외처리(옵션)
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('OTHER>'||SQLERRM);
-- 마지막(필수)
END;
/
Script Output>
PL/SQL프로시저가 성공적으로 완료되었습니다.(PL/SQL procedure successfully completed.)
v_num=0
https://wakestand.tistory.com/384
DBMS_OUTPUT.PUT_LINE 출력 안되는 경우 해결방법
DBMS_OUTPUT.PUT_LINE을 출력하려면
먼저 SET SERVEROUTPUT ON; 을 해줘야 하는데
기본 설정이 OFF라서 아무리 출력해도 나오지를 않는 것이다
SERVEROUTPUT을 ON 시킨 후 F5를 눌러서
(일반 실행은 결과 그리드만 출력함)
프로시저를 수행해 보면
DBMS_OUTPUT.PUT_LINE이 정상적으로 출력되는 것이 보인다
https://cailisin.tistory.com/149
2015년 글인데 자세히 나와있는 듯하다.
내가 받은 프로시저에는 SET SERVEROUTPUT ON이 부분이 없어서
어디에 있나 했는데
DBMS에서 한번 실행해주면 되는 것 같다..
http://www.gurubee.net/article/80048
SQL Developer
결과 텝 옆에 있는 DBMS출력 텝에서 확인하시면 됩니다.
DBMS출력 텝 좌측 상단 아이콘(DBMS출력을 사용으로 설정)을 누르면 set serveroutput on 됩니다.
[참조]
https://docs.oracle.com/cd/B19306_01/server.102/b14357/ch12040.htm
https://wakestand.tistory.com/384
https://cailisin.tistory.com/149
'차근차근 > Oracle' 카테고리의 다른 글
PL/SQL기초 (0) | 2021.12.13 |
---|---|
PL/SQL 변수선언 %type (0) | 2021.12.13 |
오라클 DUAL테이블 (가상테이블) (0) | 2021.12.10 |
오라클 반복문(3) - LOOP , WHILE , FOR,CONTINUE (0) | 2021.12.10 |
Oracle procedure (0) | 2021.12.09 |