【问题标题】:Count Total PL/SQL Code Lines without Comments计算不带注释的 PL/SQL 代码行总数
【发布时间】:2017-03-30 23:38:42
【问题描述】:

我的任务是修改一个包,在这样做的同时,我注释掉要修改的行以保留版本控制并用版本号注释它。

现在我已经完成了 Package 的修改,我想比较没有 cmets 行的 Original the Modified Scripts 的代码行总数。

在 SQL Developer / Notepad ++ / PL/SQL Developer 或任何其他免费软件 / 在线工具中是否可以使用此功能?

提前致谢!

【问题讨论】:

  • 您是否在数据库中定义/保存在表中的两个版本?
  • 嗨@DuduMarkovitz,是的,我在 TEST 中编译了两个脚本,并为新包附加了“_v1”的名称。我正在尝试查询 DBA_SOURCES,但我无法获得正确的过滤条件,因为代码被注释的方式有多种(多行、单行等)
  • 如果你注释掉版本控制的代码,你就大错特错了。这就是版本控制软件的用途。死代码应该被删除,否则你很快就会陷入可怕的混乱。
  • 嗨@JonHeller,不幸的是,我所在的当前组织没有版本控制软件。 :( 所以我只能用老方法了。
  • 我不确定这是“老办法”。我认为自 1991 年以来我所使用的每个系统都使用了源代码控制,最初是 sccs,它在 Unix 中免费提供。你不能至少将旧版本保存在一个安全的编号文本文件中吗?

标签: sql oracle plsql oracle-sqldeveloper plsqldeveloper


【解决方案1】:

你有备份包和克隆包吗。然后你可以使用“超越比较”工具。它对文本文件进行比较非常有用。您可以打开备份包和克隆包,然后轻松找到代码中的更改。

最好的问候

【讨论】:

    【解决方案2】:

    我使用 Microsoft Visual Studio 源代码管理资源管理器来比较服务器或文件系统上的版本。我推荐它胜过许多其他比较工具。附上一张示例图。

    【讨论】:

      【解决方案3】:

      基于我的一篇帖子 -
      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;
      

      【讨论】:

      • 这不适用于替代引用语法,例如:string := q'[ ' ]';
      • @MigsIsip,你检查过这个解决方案吗?
      • 嗨@DuduMarkovitz,我会检查一下。谢谢!
      猜你喜欢
      • 2017-08-02
      • 1970-01-01
      • 2018-10-07
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2017-01-19
      相关资源
      最近更新 更多