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!

Why isn't this basic loop print one line at a time ?

mike79Dec 16 2016 — edited Dec 23 2016

DB version: 12.1

For the below basic loop , I was expecting to print one line to be printed every 20 seconds (for each iteration). Instead, it waits for 60 seconds (3 loops) and prints all 3 lines together ! Why is that ?

SQL> set serveroutput on

SQL> alter session set nls_Date_format='DD-MON-YYYY HH24:MI:SS';

Session altered.

declare

v_date date;

begin

  for i in 1..3

  loop

  dbms_lock.sleep(20);

  select sysdate into v_date from dual;

  dbms_output.put_line('the date is '||v_date||'--'||i);

  end loop;

end;

/

Output :

the date is 16-DEC-2016 15:55:52--1

the date is 16-DEC-2016 15:56:12--2

the date is 16-DEC-2016 15:56:32--3

This post has been answered by BluShadow on Dec 16 2016
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 20 2017
Added on Dec 16 2016
19 comments
3,426 views