oracle 如何执行包内的程序?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/30256045/
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-19 02:52:02  来源:igfitidea点击:

How to execute a procedure which is inside a package?

oracleplsqlpackagesprocedures

提问by Ramanathan K

There is a package ABC and many procedures inside it. I want to execute a single procedure inside that (say xyz). I used the below commands

里面有一个包ABC和很多程序。我想在其中执行一个过程(比如 xyz)。我使用了以下命令

begin
ABC.xyz;
end;

I am not able to run the same. Can any one help as I am getting Unexpected symbol "BEGIN" error

我无法运行相同的。任何人都可以提供帮助,因为我收到了意外符号“BEGIN”错误

回答by Ravi

Create Package specification :

创建包规范:

create or replace package pkg is
procedure xyz;
end;

Create Package body:

创建包体

create or replace package body pkg is
procedure xyz is
dbms_output.put_line('hi');
end
end;

Executing

执行

exec pkg.xyz

OR

或者

begin
pkg.xyz;
end;

Now, verify your code and see what have you done wrong in your code.

现在,验证您的代码,看看您在代码中做错了什么。

回答by Lalit Kumar B

I want to execute a single procedure inside that (say xyz)

我想在里面执行一个程序(比如 xyz)

You can call a procedure from a package onnly if you have added it to the package specification.

只有将程序添加到程序包规范中,才能从程序包中调用过程。

From documentation,

从文档来看,

The package spec contains public declarations. The scope of these declarations is local to your database schema and global to the package. So, the declared items are accessible from your application and from anywhere in the package.

包规范包含公共声明。这些声明的范围对于您的数据库模式是本地的,对于包是全局的。因此,声明的项目可以从您的应用程序和包中的任何地方访问。

Once you add the procedure to the package spec, you could then call your procedure as package.procedure in a PL/SQL block:

将过程添加到包规范后,您就可以在PL/SQL 块中将过程作为 package.procedure 调用:

begin
   ABC.xyz;
end;

Or, in SQL*Plus:

或者,在SQL*Plus 中

EXECUTE ABC.xyz;

回答by turbogeek

To add to the great answers above: In some cases, the package is only accessible via a specific user account. In out setup we have admin and app users that have access to specific schemas and data so that our applications share a single Oracle installation. Just add the user name where your package and tables are stored.

补充上面的好答案:在某些情况下,该软件包只能通过特定的用户帐户访问。在外部设置中,我们有管理员和应用程序用户可以访问特定模式和数据,以便我们的应用程序共享单个 Oracle 安装。只需添加存储包和表的用户名。

begin user.pkg.xyz; end;

开始 user.pkg.xyz; 结尾;