0

I'm trying this anonymous block :

SET SERVEROUTOUT ON;
DECLARE
VAR_1:=1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE('Variable'||VAR_1);
VAR_1:=VAR_1+1;
EXIT WHEN VAR_1=10;
END LOOP;
END;
/

So I want that the system to print my message while it is in the loop, not when the block ends (Because it prints all the message at the end).

Thanks.

Shawn
  • 4,758
  • 1
  • 20
  • 29
  • Its an example of block, my original block its about partitioned tables (and each repetition in the loop takes a lot of time ) so that's the reason that i want my message prints while is in the loop. – Diego A. Muñoz Jan 31 '19 at 20:56
  • 1
    `DBMS_OUTPUT` only prints the result after the calling block ends. If you want to see the progress of a long-running process, you should log it to a table. AskTom recommends https://github.com/OraOpenSource/Logger – kfinity Jan 31 '19 at 21:16
  • See duplicate question https://stackoverflow.com/questions/1729739/oracle-pl-sql-tips-for-immediate-output-console-printing – kfinity Jan 31 '19 at 21:17
  • PL/SQL is not interactive. The DBMS_OUTPUT buffer is an array that is passed back to the client application at the end of the call. If you want to examine values while the code executes then you could try using the debugger. – William Robertson Jan 31 '19 at 22:57
  • Is it actually an anonymous block? If not, you could use a oracle concurrent program and get everything written in a log. – Namandeep_Kaur Feb 01 '19 at 02:07

2 Answers2

0

Add datatype for Variable

SET SERVEROUTOUT ON;
DECLARE
VAR_1 NUMBER :=1;
BEGIN
LOOP
DBMS_OUTPUT.PUT_LINE('Variable'||VAR_1);
VAR_1:=VAR_1+1;
EXIT WHEN VAR_1=10;
END LOOP;
END;
kanagaraj
  • 442
  • 1
  • 3
  • 8
0

My response has nothing to do with DBMS_OUTPUT, but it will let you watch your application as it runs. Check out DBMS_APPLICATION_INFO.SET_MODULE. It has two parameters. One is module_name, which could be used to place a 'label' on your anonymous block. The second parameter is action_name, which would let you associate a string of text to your 'label'. Action name could be set to your "'Variable'||VAR_1". You can call SET_MODULE within your loop. Then, in a separate session, you can query v$session which contains the columns MODULE and ACTION which were set using SET_MODULE.

Stilgar
  • 441
  • 2
  • 6