开发者

How to remove all comments (single line --) from code

We are dealing with long texts of code in PL/SQL and often we find that the code volume has increased just due to unneccassy comments. Most of them are single line style comments.

How do I write a script which will remove all such comment lines from the code?

For example: Original code:

DECLARE
   a  date := 0;
   -- NHT20302939 Dt 22.09.2009 Start
   b  VARCHAR2(1)  := 'N';
   -- NHT20302939 Dt 22.09.2009 End'
BEGIN
   -- NHT20302939 Dt 22.09.2009 Start
   a = GET_DATE();
   -- NHT20302939 Dt 22.09.2009 End
   if a > '22-MAR-2010' THEN
     -- NHT20302939 Dt 22.09.2009 Start
     Null;
     -- NHT20302939 Dt 22.09.2009 End
   else
      if myschema.PROCEDURE(b,
                        a) = FALSE THEN
     raise form_trigger_failure
   end if;
 end if;
END;

Desired开发者_运维百科 code:

  DECLARE
    a  date := 0;
    b  VARCHAR2(1)  := 'N';
  BEGIN
     a = GET_DATE();
     if a > '22-MAR-2010' THEN
        Null;
     else
        if myschema.PROCEDURE(b,
                              a) = FALSE THEN
           raise form_trigger_failure
        end if;
     end if;
  END;

Thnaks in advance ... Suddha Satta Ray


For stored packages, procedures etc. you could get the uncommented source like this:

select text
from   user_source
where  name = 'MYPACKAGE'
and    type = 'PACKAGE BODY'
and    ltrim(text) not like '--%'
order by line;


Try this for inline editing of file:

sed -e '/^\s*--.\+/d' -i yourFile.txt

Don't forget to backup all files before!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜