注释 Oracle 存储过程

发布于 2024-10-22 04:13:06 字数 603 浏览 4 评论 0原文

我想在 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?开发人员如何评论 SPROC。注释是否位于存储过程中?当有大量修订更改时,这看起来会很糟糕,因此寻找最佳实践和建议:-)

谢谢米克

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

-- 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 :-)

Thanks mick

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

玩套路吗 2024-10-29 04:13:06

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

您可以根据需要对打包过程进行注释,例如:

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;

问候,
抢。

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.

抹茶夏天i‖ 2024-10-29 04:13:06

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

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

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

CREATE OR REPLACE PACKAGE test_pkg AS
-- 
-- Version History
-- version date      Name  Description
-- 1.0     13/3/2011 pablo initial version
-- 
PROCEDURE proc1
裸钻 2024-10-29 04:13:06

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

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

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

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

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

 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;

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

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

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.

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.

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.

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 

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.

; cs_package_author CONSTANT VARCHAR2(30) := '$Author: MBrought

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.

; cs_package_date CONSTANT VARCHAR2(60) := '$Date: 2011-03-08 14:54:48 -0500 (Tue, 08 Mar 2011)

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.

; 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文