oracle 使用 SQL Developer 的包创建问题
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/426368/
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
Package creation issues using SQL Developer
提问by Carter
So I've never worked with stored procedures and have not a whole lot of DB experience in general and I've been assigned a task that requires I create a package and I'm stuck.
所以我从来没有使用过存储过程,并且一般没有很多数据库经验,我被分配了一项需要创建包的任务,但我被卡住了。
Using SQL Developer, I'm trying to create a package called JUMPTO with this code...
使用 SQL Developer,我正在尝试使用此代码创建一个名为 JUMPTO 的包...
create or replace package JUMPTO is
type t_locations is ref cursor;
procedure procGetLocations(locations out t_locations);
end JUMPTO;
When I run it, it spits out this PL/SQL code block...
当我运行它时,它会吐出这个 PL/SQL 代码块...
DECLARE
LOCATIONS APPLICATION.JUMPTO.t_locations;
BEGIN
JUMPTO.PROCGET_LOCATIONS(
LOCATIONS => LOCATIONS
);
-- Modify the code to output the variable
-- DBMS_OUTPUT.PUT_LINE('LOCATIONS = ' || LOCATIONS);
END;
A tutorial I found said to take out the comment for that second line there. I've tried with and without the comment.
我发现的一个教程说要删除那里第二行的评论。我试过有和没有评论。
When I hit "ok" I get the error...
当我点击“确定”时,我收到错误...
ORA-06550: line 2, column 32:
PLS-00302: component 'JUMPTO' must be declared
ORA-06550: line 2, column 13:
PL/SQL: item ignored
ORA-06550: line 6, column 18:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 5, column 3:
PL/SQL: Statement ignored
ORA-06512: at line 58
I really don't have any idea what's going on, this is all completely new territory for me. I tried creating a body that just selected some stuff from the database but nothing is working the way it seems like it should in my head. Can anyone give me any insight into this?
我真的不知道发生了什么,这对我来说都是全新的领域。我尝试创建一个刚刚从数据库中选择一些东西的主体,但没有任何东西像我脑海中的那样工作。任何人都可以让我对此有任何见解吗?
回答by FerranB
First of all you need to declare a package body, for instance:
首先你需要声明一个包体,例如:
create or replace package body JUMPTO is
procedure procGetLocations(locations out t_locations)
is
begin
locations := null; -- Need code here
end;
end JUMPTO;
To compile need this:
编译需要这个:
DECLARE
LOCATIONS JUMPTO.t_locations;
BEGIN
JUMPTO.PROCGETLOCATIONS(
LOCATIONS => LOCATIONS
);
END;
回答by ropable
An Oracle PL/SQL package has 2 parts:
Oracle PL/SQL 包有 2 个部分:
- A package specification (the public part, where globally accessible constants, functions, procedures, variables, etc are listed).
- A package body (where the code resides to implement the package spec).
- 包规范(公共部分,其中列出了可全局访问的常量、函数、过程、变量等)。
- 包体(代码所在的位置以实现包规范)。
Your first piece of code declared the package specification (JUMPTO). You declared a type (t_locations) and a procedure (procGetLocations) that has no inputs, but outputs one variable (locations) of type t_locations.
您的第一段代码声明了包规范 ( JUMPTO)。您声明了一个类型 ( t_locations) 和一个没有输入但输出一个类型为 t_locations 的变量 ( locations) 的过程 ( procGetLocations) 。
First compile the package spec (as you did), then compile the package body like so:
首先编译包规范(就像你所做的那样),然后像这样编译包体:
create or replace package body JUMPTO is
procedure procGetLocations(locations out t_locations) is
begin
locations := null; -- Your code goes here
end procGetLocations;
end JUMPTO;
Now you can call the procedure procGetLocationsin other PL/SQL blocks (anonymous or otherwise).
现在您可以在其他 PL/SQL 块(匿名或其他方式)中调用过程procGetLocations。