Christoph's 2 Cents

A Backup for My Brain!

Oracle DevelopementPL/SQL

Neat little comment trick.

I often have some test code that spans multiple lines in my PL/SQL programs that I need to comment/un-comment frequently.

When placing the comment marks (/* */) at the beginning and the end of the test code, you always have to know where the first and last lines of the code are in order to comment/un-comment them.

With this little trick, you only need to know where the test code section starts, and the end of the code section comments/un-comments it self!.

All you have to do is place a line comment (–) in front of the end comment (*/).
If you now place a line comment in front of the begin comment (/*), the code section becomes active (un-commented). If you then remove the line comment (–) from the begin comment (/*), the code section will be commented out.

Commented out:

DECLARE
 l_count NUMBER := 0;
 BEGIN
 /*
 SELECT COUNT(*)
   INTO l_count
   FROM user_objects;
 --*/
  dbms_output.put_line('I counted ' || l_count);
END;

Code not commented out:

DECLARE
 l_count NUMBER := 0;
 BEGIN
 --/*
 SELECT COUNT(*)
   INTO l_count
   FROM user_objects;
 --*/
dbms_output.put_line('I counted ' || l_count);
END;

So by commenting/un-commenting the first comment (/*), the entire code section gets affected.