Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why do I see no output from this PL/SQL block?

I'd like a code sample.

I'm tryng this:

DECLARE
     var NUMBER;
 BEGIN
     /*N.B. for loop variables in pl/sql are new declarations, with scope only inside the loop */ 
     FOR var IN 0 .. 10 LOOP 
          DBMS_OUTPUT.put_line(var);
     END LOOP;

     IF (var IS NULL) THEN
          DBMS_OUTPUT.put_line('var is null');
     ELSE
          DBMS_OUTPUT.put_line('var is not null');
     END IF;
 END;

and getting no output (though I know it's not a infinite loop). Why is this one not printing?

edit: The not-printing code was fixed via the database manager interface.

like image 750
andandandand Avatar asked Nov 29 '22 05:11

andandandand


1 Answers

A LOOP without an EXIT statement is one way to generate an infinite loop in PL/SQL

BEGIN
  LOOP
    null;
  END LOOP;
END;

You could also write a WHILE loop that never ends

BEGIN
  WHILE( true )
  LOOP
    NULL;
  END LOOP;
END;
like image 98
Justin Cave Avatar answered Dec 06 '22 19:12

Justin Cave