oracle 如何在包体中运行过程
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12563752/
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
How to run a procedure in a package body
提问by Sam
I am using oracle 11g . I am trying to run a procedure inside a package by using the command
我正在使用 oracle 11g 。我正在尝试使用以下命令在包内运行一个过程
execute package.procedure
but I keep getting the exception
但我不断收到例外
ERROR at line 1:
ORA-06550: line 1, column 12:
PLS-00302: component 'package' must be declared
ORA-06550: line 1, column 7:
PL/SQL: Statement ignored
The package and package body i created is the following. What i am actually trying to do here is to create a package which is used to create tables each time its executed. so i wrote the following script.
我创建的包和包体如下。我在这里真正想做的是创建一个包,用于在每次执行时创建表。所以我写了以下脚本。
-----Package
- - -包裹
create or replace package pack1 as
end pack1 ;
/
------Package Body
------包体
create or replace package body pack1 as
procedure proc1
is
begin
execute immediate 'create table bcd(bc date)';
end ;
procedure proc2
is
begin
execute immediate 'create table bcde(bc number(12,0)) as select country_id from countries';
end ;
end pack1;
/
but when i ran
但是当我跑
execute pack1.proc2 ;
It gave me the above exception.
它给了我上述例外。
Can someone help me with what is wrong ?
有人可以帮我解决什么问题吗?
Thanks a ton in advance
提前致谢
回答by Alex Poole
Procedures and functions in a package are private by default. To make them public you have to declare them in the package specification:
包中的过程和函数默认是私有的。要使它们公开,您必须在包规范中声明它们:
create or replace package pack1 as
procedure proc1;
procedure proc2;
end pack1;
/
Creating tables on the fly doesn't sounds like a good idea though.
不过,动态创建表格听起来不是一个好主意。