Oracle中的存储过程和独立过程之间有什么区别? [英] What is the difference between stored procedure and standalone procedure in Oracle?

查看:148
本文介绍了Oracle中的存储过程和独立过程之间有什么区别?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

create procedure proc1
(
begin

end;
)

存储过程

create package pkg1
(
procedure proc2
begin

end;
)

推荐答案

来自oracle文档中的

From the oracle documentation for CREATE PROCEDURE

独立过程是存储在数据库中的过程(执行特定操作的子程序).

A standalone procedure is a procedure (a subprogram that performs a specific action) that is stored in the database.

嵌套过程是位于PL/SQL块或程序包.

A nested procedure is a procedure that is in a PL/SQL block or a package.

CREATE PACKAGE 文档中:

CREATE PACKAGE语句创建或替换存储程序包的规范,该程序包是相关过程,函数以及其他作为单元存储在数据库中的其他程序对象的封装集合.包规范声明了这些对象.随后指定的程序包主体定义了这些对象.

The CREATE PACKAGE statement creates or replaces the specification for a stored package, which is an encapsulated collection of related procedures, functions, and other program objects stored as a unit in the database. The package specification declares these objects. The package body, specified subsequently, defines these objects.

独立过程和嵌套在程序包中的过程都存储(编译)在数据库中-存储"过程也是如此.在匿名PL/SQL块中定义的过程不是存储"过程.

Standalone procedures and procedures nested in a package are both stored (compiled) within the database - so are "stored" procedures. Procedures defined in an anonymous PL/SQL block are not "stored" procedures.

这不是存储过程:

DECLARE
  n NUMBER := 1;

  PROCEDURE incr( a IN OUT NUMBER ) IS
  BEGIN
    a := a + 1;
  END;
BEGIN
  incr(n);
  DBMS_OUTPUT.PUT_LINE(n);
END;
/

程序包中的嵌套过程与独立过程之间没有太大区别:

There is not a huge difference between nested procedures in packages and standalone procedures:

  • 使用CREATE PROCEDURE ...定义独立过程,而使用PROCEDURE ...在PL/SQL块中定义嵌套过程.
  • 独立过程始终需要过程定义(AS BEGIN ... END;部分),但程序包中的(公共)嵌套过程仅声明过程标题(PROCEDURE NAME(...)部分),然后在程序包主体中将重新声明该标题并定义过程定义.
  • 在包中嵌套过程可以使它具有相似的功能,并且可以访问包专有的功能,过程和数据(即,在包主体中定义,但不在公共包规范中定义). /li>
  • A standalone procedure is defined using CREATE PROCEDURE ... whereas a nested procedure is defined within the PL/SQL block using PROCEDURE ....
  • A standalone procedure always requires a procedure definition (the AS BEGIN ... END; part) but a (public) nested procedure in a package only declares the procedure heading (the PROCEDURE NAME(...) part) and then in the package body will restate the heading and define the procedure definition.
  • Nesting a procedure in a package allows it to be grouped with similar functionality and allows it to access functions, procedures and data which is private to the package (i.e. defined in the package body but not in the public package specification).

这篇关于Oracle中的存储过程和独立过程之间有什么区别?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆