所以我从来没有使用过存储过程,并且一般没有大量的数据库经验,而且我被分配了一个任务,需要我创建一个包而且我被卡住了。
使用SQL Developer,我正在尝试使用此代码创建一个名为JUMPTO的包...
create or replace package JUMPTO is
type t_locations is ref cursor;
procedure procGetLocations(locations out t_locations);
end JUMPTO;
当我运行它时,它会吐出这个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;
我找到的一个教程说要在那里取出第二行的评论。我已经尝试过没有评论。
当我点击“确定”时,我收到错误...
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
我真的不知道发生了什么,这对我来说都是一个全新的领域。我尝试创建一个刚刚从数据库中选择一些东西的主体,但没有任何东西像我脑子里想象的那样工作。任何人都可以给我任何洞察力吗?
答案 0 :(得分:2)
首先,您需要声明一个包体,例如:
create or replace package body JUMPTO is
procedure procGetLocations(locations out t_locations)
is
begin
locations := null; -- Need code here
end;
end JUMPTO;
编译需要这个:
DECLARE
LOCATIONS JUMPTO.t_locations;
BEGIN
JUMPTO.PROCGETLOCATIONS(
LOCATIONS => LOCATIONS
);
END;
答案 1 :(得分:2)
Oracle PL / SQL包有两部分:
您的第一段代码声明了包规范( JUMPTO )。您声明了一个类型( t_locations )和一个没有输入的过程( procGetLocations ),但是输出了一个类型为t_locations的变量( locations )。
首先编译包规范(就像你一样),然后像这样编译包体:
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;
现在您可以在其他PL / SQL块(匿名或其他)中调用 procGetLocations 过程。