基于我的一篇帖子 -
SQL/Regex Challenge/Puzzle: How to remove comments from SQL code (by using SQL query)?
create or replace package dmarkovitz.old_code as
1
2 2
3
/* yada yada yada */
4
5 '-- not a comment '
6
-- bla bla bla
7
8 "/* also not a comment"
9
10 'and again, not a comment */'
end;
/
create or replace package dmarkovitz.new_code as
1
2 /* bla bla bla */ 2
-- 3
/* yada yada yada */
4
5 '-- not a comment '
/*6
-- bla bla bla
7
8 "/* also not a comment"
9 */
10 'and again, not a comment */'
end;
select owner
,object_name
,object_type
,ddl
,uncommented_ddl
,regexp_count (uncommented_ddl,chr(10)) as lines
from (select owner
,object_name
,object_type
,ddl
,regexp_replace (ddl,'(''.*?''|".*?")|/\s*\*.*?\*/\s*|\s*--.*?(?=$|\z)','\1',1,0,'mn') as uncommented_ddl
from (select owner
,object_name
,object_type
,dbms_metadata.get_ddl (object_type,object_name,owner) as ddl
from all_objects
where owner = 'DMARKOVITZ'
and object_name in ('OLD_CODE','NEW_CODE')
and object_type = 'PACKAGE'
)
)
;
OWNER OBJECT_NAME OBJECT_TYPE DDL UNCOMMENTED_DDL LINES
---------- ----------- ----------- ---- --------------- -----
DMARKOVITZ NEW_CODE PACKAGE CLOB CLOB 8
DMARKOVITZ OLD_CODE PACKAGE CLOB CLOB 13
OLD_CODE uncommented_ddl
CREATE OR REPLACE PACKAGE "DMARKOVITZ"."OLD_CODE" as
1
2 2
3
4
5 '-- not a comment '
6
7
8 "/* also not a comment"
9
10 'and again, not a comment */'
end;
NEW_CODE uncommented_ddl
CREATE OR REPLACE PACKAGE "DMARKOVITZ"."NEW_CODE" as
1
2 2
4
5 '-- not a comment '
10 'and again, not a comment */'
end;