Neat little comment trick.

November 7, 2012 at 5:55 pm | Posted in Oracle Developement, PL/SQL | Leave a comment
Tags: , ,

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.

Advertisements

Leave a Comment »

RSS feed for comments on this post. TrackBack URI

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Blog at WordPress.com.
Entries and comments feeds.

%d bloggers like this: