注释 Oracle 存储过程

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/5310184/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-18 23:03:53  来源:igfitidea点击:

Commenting an Oracle stored procedure

oracleoracle10g

提问by Dtheitroademik

I want to comment a stored procedure in Oracle something like this

我想像这样评论 Oracle 中的存储过程

-- MODIFICATION HISTORY
-- Person           Date            Comments
-- ---------        ------          ------------------------------------------
-- MICK             09/15/2010      New Sproc

CREATE OR REPLACE PROCEDURE INTERMISSIONS(
                            p_Myid        IN NUMBER,
                            p_Mytype      IN NUMBER,
                            p_recordset         OUT GET_RESULTS_BY_ID_PKG.get_by_id_cursor)

How do you do this in Oracle? How do developers comment a SPROC. Do the comment sit inside the stored procedure? This will look terrible when there are loads of revision changes so looking for best practice and advice :-)

您如何在 Oracle 中执行此操作?开发人员如何评论 SPROC。注释是否位于存储过程中?当有大量修订更改时,这看起来会很糟糕,因此请寻求最佳实践和建议:-)

Thanks mick

谢谢米克

回答by Rob van Wijk

Comments are yet another reason to stay away from stored procedures, and use packages instead.

注释是远离存储过程而使用包的另一个原因。

You can comment a packaged procedure just like you want, for example:

您可以随意评论打包的过程,例如:

CREATE OR REPLACE PACKAGE your_package
AS
  --
  -- MODIFICATION HISTORY
  -- Person           Date           Comments
  -- ---------        ------         ------------------------------------------
  -- MICK             09/15/2010     Created new packaged procedure INTERMISSIONS
  --  
  PROCEDURE INTERMISSIONS
  ( p_Myid      IN  NUMBER
  , p_Mytype    IN  NUMBER
  , p_recordset OUT GET_RESULTS_BY_ID_PKG.get_by_id_cursor
  );
END your_package;

Regards,
Rob.

问候,
罗伯。

回答by pablo

I always package my procedures and add comments containing version history immediately after the package/package body statement

我总是打包我的程序并在 package/package body 语句之后立即添加包含版本历史的注释

CREATE OR REPLACE PACKAGE test_pkg AS
-- 
-- Version History
-- version date      Name  Description
-- 1.0     13/3/2011 pablo initial version
-- 
PROCEDURE proc1

回答by Michael Broughton

If you want the version info stored in the file, then you can do it as you are. But if you want it stored in the database then it needs to exist as a comment inside the actual proc or Oracle will not store it.

如果您希望将版本信息存储在文件中,那么您可以按原样进行。但是,如果您希望它存储在数据库中,那么它需要作为实际过程中的注释存在,否则 Oracle 不会存储它。

I don't know why anyone wants to keep all of the version history inside the proc though. Isn't that what your version control system is for? And that history is just comments anyway, you still need to go back to diff against your previous version if you want to see the actual code changes.

我不知道为什么有人想将所有版本历史记录保存在 proc 中。这不是您的版本控制系统的用途吗?无论如何,历史只是评论,如果您想查看实际的代码更改,您仍然需要返回与以前版本的差异。

I generally set up tags for the version control system in comments in the declaration section so that the version control system updates it automatically. This way I can always see what the current version is, and that is enough.

我通常在声明部分的注释中为版本控制系统设置标签,以便版本控制系统自动更新它。这样我总能看到当前版本是什么,这就足够了。

Indeed, on my current project the standard exception handling/logging system we built grabs the version info from variables in our API packages so that we can tie recorded code errors to software versions. The variables get updated automatically through the tags that the version control system recognizes.

事实上,在我当前的项目中,我们构建的标准异常处理/日志系统从 API 包中的变量中获取版本信息,以便我们可以将记录的代码错误与软件版本联系起来。变量通过版本控制系统识别的标签自动更新。

e.g. each package has the following:

例如,每个包都有以下内容:

 create or replace package body pkg_payment_api as  
   cs_package_name     CONSTANT VARCHAR2(60) :='pkg_payment_api';
   cs_package_version  CONSTANT VARCHAR2(30) := '$Rev: 24992 $';
   cs_package_author   CONSTANT VARCHAR2(30) := '$Author: MBrought $';
   cs_package_date     CONSTANT VARCHAR2(60) := '$Date: 2011-03-08 14:54:48 -0500 (Tue, 08 Mar 2011) $';

   FUNCTION get_package_version
   RETURN varchar2
   IS
   BEGIN
        RETURN 'Version: '||cs_package_version || ' Author: ' ||cs_package_author || ' Timestamp: '||cs_package_date;
   END get_package_version;

And every public function and procedure in that package has an exception handler that calls a common logging routine which will store the exception, time, version info, and other relevant information.

并且该包中的每个公共函数和过程都有一个异常处理程序,它调用一个公共日志记录例程,该例程将存储异常、时间、版本信息和其他相关信息。

But no way am I storing all of the version hisotry info in the database. The database just needs the current build and a means to identify its component versions - that's all.

但是我无法将所有版本历史信息存储在数据库中。数据库只需要当前的构建和识别其组件版本的方法——仅此而已。