From e85da179b2ede3c204052d0b82def70bb78b1fea Mon Sep 17 00:00:00 2001 From: Yafei Wu Date: Tue, 25 Oct 2022 23:28:53 +0800 Subject: [PATCH] fix dbms_output.serveroutput(true) clear the buffer.It conforms to the features of oracle. --- expected/dbms_output.out | 137 +++++++++++++++++++++++++++------------ putline.c | 22 +++++-- sql/dbms_output.sql | 111 +++++++++++++++++++------------ 3 files changed, 183 insertions(+), 87 deletions(-) diff --git a/expected/dbms_output.out b/expected/dbms_output.out index 0ae40d42e979..cda56cd4b4fc 100644 --- a/expected/dbms_output.out +++ b/expected/dbms_output.out @@ -130,9 +130,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -165,9 +164,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -207,9 +205,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -246,9 +244,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -285,9 +283,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1 '); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); @@ -322,9 +319,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); @@ -358,9 +355,8 @@ DECLARE buff3 VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); @@ -400,9 +396,8 @@ DECLARE buff2 VARCHAR(20); stts INTEGER := 2; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); @@ -438,9 +433,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -477,9 +471,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -516,9 +509,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -555,9 +547,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); @@ -589,9 +580,9 @@ DECLARE buff2 VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT ('ORA'); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.PUT ('FCE'); @@ -625,9 +616,8 @@ DECLARE buff1 VARCHAR(3000); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.ENABLE(2000); FOR j IN 1..1999 LOOP PERFORM DBMS_OUTPUT.PUT ('A'); @@ -660,9 +650,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); @@ -732,9 +721,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -764,9 +752,9 @@ DECLARE status INTEGER; num INTEGER := 2000; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.ENABLE(2000); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.NEW_LINE(); @@ -794,9 +782,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); @@ -831,9 +819,9 @@ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); @@ -918,9 +906,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -1041,3 +1029,72 @@ ORAFCE TEST 1 (1 row) DROP FUNCTION dbms_output_test(); +-- SERVEROUTPUT [4] SERVEROUTPUT('t') get_line return null +CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); +CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ +DECLARE + buff VARCHAR(20); + stts INTEGER; +BEGIN + PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); + SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); + INSERT INTO dbms_output_test VALUES (buff, stts); + SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); + INSERT INTO dbms_output_test VALUES (buff, stts); + PERFORM DBMS_OUTPUT.DISABLE(); + PERFORM DBMS_OUTPUT.ENABLE(); +END; +$$ LANGUAGE plpgsql; +SELECT dbms_output_test(); +ORAFCE TEST 1 +ORAFCE TEST 2 + dbms_output_test +------------------ + +(1 row) + +SELECT * FROM dbms_output_test; + buff | status +--------+-------- + | 1 + | 1 +(2 rows) + +DROP TABLE dbms_output_test; +DROP FUNCTION dbms_output_test(); +-- test dbms_output.serveroutput(false) clear buffer +select dbms_output.serveroutput(true); + serveroutput +-------------- + +(1 row) + +do $$ +BEGIN + PERFORM DBMS_OUTPUT.PUT_LINE('1234242'); +END$$; +1234242 +select dbms_output.serveroutput(false); + serveroutput +-------------- + +(1 row) + +do $$ +BEGIN + PERFORM DBMS_OUTPUT.PUT_LINE('1234242'); +END$$; +select dbms_output.serveroutput(true); + serveroutput +-------------- + +(1 row) + +do $$ +BEGIN + PERFORM DBMS_OUTPUT.PUT_LINE('1234242'); +END$$; +1234242 diff --git a/putline.c b/putline.c index 59b64469cddf..e78caa7b5e46 100644 --- a/putline.c +++ b/putline.c @@ -162,6 +162,18 @@ dbms_output_enable_internal(int32 n_buf_size) } } +static void +dbms_output_disable_internal() +{ + if (buffer) + pfree(buffer); + + buffer = NULL; + buffer_size = 0; + buffer_len = 0; + buffer_get = 0; +} + PG_FUNCTION_INFO_V1(dbms_output_enable_default); Datum @@ -206,13 +218,7 @@ PG_FUNCTION_INFO_V1(dbms_output_disable); Datum dbms_output_disable(PG_FUNCTION_ARGS) { - if (buffer) - pfree(buffer); - - buffer = NULL; - buffer_size = 0; - buffer_len = 0; - buffer_get = 0; + dbms_output_disable_internal(); PG_RETURN_VOID(); } @@ -224,6 +230,8 @@ dbms_output_serveroutput(PG_FUNCTION_ARGS) is_server_output = PG_GETARG_BOOL(0); if (is_server_output && !buffer) dbms_output_enable_internal(BUFSIZE_DEFAULT); + else if (!is_server_output && buffer) + dbms_output_disable_internal(); PG_RETURN_VOID(); } diff --git a/sql/dbms_output.sql b/sql/dbms_output.sql index c46088ce3054..d8ded4cc7cc7 100644 --- a/sql/dbms_output.sql +++ b/sql/dbms_output.sql @@ -99,9 +99,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -124,9 +123,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -154,9 +152,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -182,9 +180,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -210,9 +208,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1 '); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); @@ -237,9 +234,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); @@ -264,9 +261,8 @@ DECLARE buff3 VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); @@ -294,9 +290,8 @@ DECLARE buff2 VARCHAR(20); stts INTEGER := 2; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 3'); @@ -321,9 +316,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -349,9 +343,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -377,9 +370,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -405,9 +397,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 1; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORA F CE'); @@ -430,9 +421,9 @@ DECLARE buff2 VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT ('ORA'); PERFORM DBMS_OUTPUT.NEW_LINE(); PERFORM DBMS_OUTPUT.PUT ('FCE'); @@ -456,9 +447,8 @@ DECLARE buff1 VARCHAR(3000); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.ENABLE(2000); FOR j IN 1..1999 LOOP PERFORM DBMS_OUTPUT.PUT ('A'); @@ -482,9 +472,8 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); @@ -541,9 +530,8 @@ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); SELECT INTO buff,stts lines[1],numlines FROM DBMS_OUTPUT.GET_LINES(stts); @@ -564,9 +552,9 @@ DECLARE status INTEGER; num INTEGER := 2000; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.ENABLE(2000); PERFORM DBMS_OUTPUT.PUT ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.NEW_LINE(); @@ -585,9 +573,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); @@ -612,9 +600,9 @@ DECLARE buff VARCHAR(20); stts INTEGER := 10; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.DISABLE(); PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); @@ -676,9 +664,9 @@ DECLARE buff VARCHAR(20); stts INTEGER; BEGIN - PERFORM DBMS_OUTPUT.DISABLE(); - PERFORM DBMS_OUTPUT.ENABLE(); PERFORM DBMS_OUTPUT.SERVEROUTPUT ('f'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); PERFORM DBMS_OUTPUT.ENABLE(); SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); @@ -762,3 +750,46 @@ END; $$ LANGUAGE plpgsql; SELECT dbms_output_test(); DROP FUNCTION dbms_output_test(); + +-- SERVEROUTPUT [4] SERVEROUTPUT('t') get_line return null +CREATE TABLE dbms_output_test (buff VARCHAR(20), status INTEGER); +CREATE FUNCTION dbms_output_test() RETURNS VOID AS $$ +DECLARE + buff VARCHAR(20); + stts INTEGER; +BEGIN + PERFORM DBMS_OUTPUT.SERVEROUTPUT ('t'); + PERFORM DBMS_OUTPUT.ENABLE(); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 1'); + PERFORM DBMS_OUTPUT.PUT_LINE ('ORAFCE TEST 2'); + SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); + INSERT INTO dbms_output_test VALUES (buff, stts); + SELECT INTO buff,stts line,status FROM DBMS_OUTPUT.GET_LINE(); + INSERT INTO dbms_output_test VALUES (buff, stts); + PERFORM DBMS_OUTPUT.DISABLE(); + PERFORM DBMS_OUTPUT.ENABLE(); +END; +$$ LANGUAGE plpgsql; +SELECT dbms_output_test(); +SELECT * FROM dbms_output_test; +DROP TABLE dbms_output_test; +DROP FUNCTION dbms_output_test(); + +-- test dbms_output.serveroutput(false) clear buffer +select dbms_output.serveroutput(true); +do $$ +BEGIN + PERFORM DBMS_OUTPUT.PUT_LINE('1234242'); +END$$; + +select dbms_output.serveroutput(false); +do $$ +BEGIN + PERFORM DBMS_OUTPUT.PUT_LINE('1234242'); +END$$; + +select dbms_output.serveroutput(true); +do $$ +BEGIN + PERFORM DBMS_OUTPUT.PUT_LINE('1234242'); +END$$;