Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

SET SERVEROUTPUT strange behaviour

824574Feb 3 2011 — edited Feb 4 2011
Hello.

Oracle Database 10g Enterprise Edition Release 10.2.0.4.0 - 64bi
PL/SQL Release 10.2.0.4.0 - Production

We have a pl/sql block, which does the following:

- sets serveroutput on
- loop through a cursor
- perform an update
- output updated rows count
- commit

Everything works but the dbms_output commands.

The strange thing is, running the script TWICE in the same session produces the output! It's as if SERVEROUTPUT isn't being set until the second run. We've commented out the update statement - and then dbms_output works!

Here's the code:

SET SERVEROUTPUT ON
DECLARE
v_upd_date DATE := SYSDATE;
v_upd_count NUMBER := 0;
BEGIN
dbms_output.put_line('ABC');
FOR c IN (SELECT
ENTITY_CODE
,ENTITY_TYPE
,REGION
,TRADE_ETD_FLAG
,FX_ETD_FLAG
,FX_ETC_FLAG
,TAP_FLAG
,CLS_FLAG
FROM PORG_ATT_STG
where entity_code = 'AU00002')
LOOP
dbms_output.put_line('c.entity_code ' || c.entity_code);
v_upd_count := v_upd_count + 1;
UPDATE entity_extension
SET
user_ind62 = 'Y'
,user_ind63 = 'Y'
,user_ind65 = 'Y'
,user_ind66 = 'Y'
,user_ind68 = 'Y'
WHERE trim(entity_id) = (SELECT distinct trim(e.Entity_id)
FROM rulesdbo.entity_extension ee
,rulesdbo.entity e
WHERE e.Entity_Id = ee.Entity_Id
AND e.Entity_Type = c.Entity_Type
AND trim(e.Entity_Code) = trim(c.Entity_Code));
END LOOP;
dbms_output.put_line(v_upd_count);
COMMIT;
END;
/

Any suggestions gratefully receieved; we've been going bonkers on this one.

Thanks
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Mar 4 2011
Added on Feb 3 2011
28 comments
2,382 views