-
Notifications
You must be signed in to change notification settings - Fork 0
Description
Oracle DBMS_OUTPUT: Multiple ENABLE() Calls Behavior
Tested on: Oracle Database 23.26 Free
Date: 2025-12-25
Overview
This report documents the behavior when DBMS_OUTPUT.ENABLE() is called multiple times within a session, based on empirical testing against a real Oracle database.
Oracle Documentation states: "If there are multiple calls to ENABLE, then buffer_size is the last of the values specified."
1. Basic Behavior
| Behavior | Result |
|---|---|
| Multiple ENABLE calls | Buffer content is preserved (not cleared) |
| Buffer size | Last specified value becomes the limit |
| Only DISABLE clears | DISABLE() is the only way to clear buffer content |
DBMS_OUTPUT.DISABLE;
DBMS_OUTPUT.ENABLE(5000);
DBMS_OUTPUT.PUT_LINE('Line 1');
DBMS_OUTPUT.ENABLE(10000); -- Buffer NOT cleared
DBMS_OUTPUT.PUT_LINE('Line 2');
-- Output: Both lines appear2. Shrinking Buffer Size
When calling ENABLE(smaller_size) after ENABLE(larger_size):
2.1 Empty Buffer
New smaller limit is enforced strictly.
DBMS_OUTPUT.DISABLE;
DBMS_OUTPUT.ENABLE(5000);
DBMS_OUTPUT.ENABLE(2500); -- Shrink while empty
DBMS_OUTPUT.PUT_LINE(RPAD('X', 2600, 'X')); -- FAILS: exceeds 25002.2 Buffer Content < New Limit
New limit is enforced for total (existing + new).
DBMS_OUTPUT.DISABLE;
DBMS_OUTPUT.ENABLE(5000);
DBMS_OUTPUT.PUT_LINE(RPAD('X', 1000, 'X')); -- 1000 bytes
DBMS_OUTPUT.ENABLE(2000); -- Shrink to 2000
DBMS_OUTPUT.PUT_LINE(RPAD('Y', 1500, 'Y')); -- FAILS: 1000+1500 > 20002.3 Buffer Content >= New Limit (Key Finding)
Additive capacity behavior: When existing content already exceeds the new limit, Oracle expands capacity to approximately first_size + second_size.
DBMS_OUTPUT.DISABLE;
DBMS_OUTPUT.ENABLE(4000);
DBMS_OUTPUT.PUT_LINE(RPAD('X', 3500, 'X')); -- 3500 > 3000
DBMS_OUTPUT.ENABLE(3000); -- Shrink, but content exceeds new limit
-- Effective capacity becomes ~7000 (4000 + 3000)
DBMS_OUTPUT.PUT_LINE(RPAD('Y', 3000, 'Y')); -- OK: total ~6500 < 7000| First ENABLE | Second ENABLE | Content before shrink | Effective Capacity |
|---|---|---|---|
| 3000 | 2500 | > 2500 | ~5500 |
| 4000 | 3000 | > 3000 | ~7000 |
3. Effect of GET_LINES() After Shrinking
After GET_LINES() flushes the buffer, the additive capacity is lost. The limit reverts to the last ENABLE value.
DBMS_OUTPUT.DISABLE;
DBMS_OUTPUT.ENABLE(4000);
DBMS_OUTPUT.PUT_LINE(RPAD('X', 3500, 'X'));
DBMS_OUTPUT.ENABLE(3000); -- Additive: capacity ~7000
DBMS_OUTPUT.GET_LINES(lines, numlines); -- Flush
-- Capacity now reverts to 3000
DBMS_OUTPUT.PUT_LINE(RPAD('Y', 2999, 'Y')); -- OK
DBMS_OUTPUT.PUT_LINE('Z'); -- OK (total 3000)
DBMS_OUTPUT.PUT_LINE('A'); -- FAILS: exceeds 30004. Buffer Reuse After GET_LINES()
GET_LINES() frees buffer space. The limit applies to current contents, not cumulative lifetime writes.
DBMS_OUTPUT.DISABLE;
DBMS_OUTPUT.ENABLE(2000);
DBMS_OUTPUT.PUT_LINE(RPAD('X', 1500, 'X')); -- 1500
DBMS_OUTPUT.GET_LINES(lines, numlines); -- Flush
DBMS_OUTPUT.PUT_LINE(RPAD('Y', 1500, 'Y')); -- OK: buffer was cleared
DBMS_OUTPUT.GET_LINES(lines, numlines); -- Flush again
DBMS_OUTPUT.PUT_LINE(RPAD('Z', 1500, 'Z')); -- OK: can reuse indefinitely5. Summary Table
| Scenario | Buffer Cleared? | Effective Limit |
|---|---|---|
ENABLE(A) then ENABLE(B) (empty buffer) |
No | B |
ENABLE(A) -> write -> ENABLE(B) where B > content |
No | B |
ENABLE(A) -> write -> ENABLE(B) where B <= content |
No | ~A+B (additive) |
After GET_LINES() flush |
Yes (content) | Last ENABLE value |
DISABLE() |
Yes | N/A (disabled) |
6. Practical Implications
-
Don't rely on shrinking: Calling
ENABLE(smaller)doesn't reclaim memory or enforce the smaller limit if content already exceeds it. -
Use DISABLE to reset: If you need a clean slate, call
DISABLE()first. -
GET_LINES resets capacity: After flushing, the additive capacity bonus is lost.
-
Application code should avoid ENABLE/DISABLE: Per Oracle documentation, these calls can interfere with tools like SQL*Plus that manage output display.
7. Buffer Size Constraints
| Parameter | Value |
|---|---|
| Minimum size | 2,000 bytes |
| Maximum size | 1,000,000 bytes |
| Default | 20,000 bytes |
| Unlimited | NULL |