我可以编译规范和正文,但无法执行该过程 任何帮助将不胜感激。
CREATE OR REPLACE PACKAGE TEST_PKG
IS
type chef_type is RECORD
(
p_var1 varchar2(3)
p_date vachar2(8)
);
type chef_array is varray(1000) of chef_type;
PROCEDURE TEST_PROC (
p_num_chef IN NUMBER,
p_chef IN chef_array,
p_erreur OUT NUMBER,
p_message OUT VARCHAR2
);
END TEST_PKG;
/
CREATE OR REPLACE PACKAGE BODY TEST_PKG
IS
PROCEDURE TEST_PROC (
p_num_chef IN NUMBER,
p_chef IN chef_array,
p_erreur OUT NUMBER,
p_message OUT VARCHAR2
)
IS
v_...
BEGIN
FOR i IN 1 .. p_num_chef
LOOP
v_var1 := p_chef(i).p_var1;
v_date := p_chef(i).p_date;
END LOOP;
END TEST_PROC;
END TEST_PKG;
/
-- E X E C U T E P R O C E D U R E
DECLARE
v_erreur NUMBER :=0;
v_message VARCHAR2(256) := '';
p_erreur NUMBER;
p_message VARCHAR2(256);
BEGIN
TEST_PROC(
2 -- p_num_chef
,'ABC' -- p_chef(1).p_var1
,'20241120' -- p_chef(1).p_date
,'DEF' -- p_chef(2).p_var1
,'20241120' -- p_chef(2).p_date
,v_erreur -- p_erreur
,v_message -- p_message
);
dbms_output.put_line('p_erreur: ' || p_erreur);
dbms_output.put_line('p_message: ' || p_message);
END;
[错误]执行(39:1):ORA-06550:第n行,第1列: PLS-00306:调用“TEST_PROC”时参数数量或类型错误
基本上我正在尝试调用包含数组的存储过程,但出现错误
这里的主要问题是您尝试使用包内声明的类型 - 包外声明的类型。如果您像问题中那样调用包过程,则首先在 SQL 中创建类型,以使它们可供包和调用 PLSQL 块使用。
Create or Replace type chef_type is OBJECT( p_var1 varchar2(3), p_date date );
Create or Replace Type chef_tbl is TABLE OF chef_type;
...接下来创建包...
create or replace PACKAGE
TEST_PKG IS
PROCEDURE TEST_PROC (
p_num_chef IN NUMBER,
p_chef IN chef_tbl,
p_var1 OUT VARCHAR2,
p_date OUT DATE
);
END TEST_PKG;
create or replace PACKAGE BODY TEST_PKG
IS
PROCEDURE TEST_PROC (
p_num_chef IN NUMBER,
p_chef IN chef_tbl,
p_var1 OUT VARCHAR2,
p_date OUT DATE
)
IS
BEGIN
FOR i IN 1 .. p_num_chef
LOOP
p_var1 := p_chef(i).p_var1;
p_date := p_chef(i).p_date;
END LOOP;
END TEST_PROC;
END TEST_PKG;
...并调用打包程序...
-- E X E C U T E P R O C E D U R E
DECLARE
v_var1 VARCHAR2(3);
v_date DATE;
v_chef_tbl chef_tbl := chef_tbl();
BEGIN
v_chef_tbl.Extend();
v_chef_tbl(1) := chef_type('ABC', SYSDATE-1);
TEST_PKG.TEST_PROC( p_num_chef => 1,
p_chef => v_chef_tbl,
p_var1 => v_var1,
p_date => v_date );
dbms_output.put_line('p_var1: ' || v_var1);
dbms_output.put_line('p_date: ' || v_date);
--
v_chef_tbl.Extend();
v_chef_tbl(2) := chef_type('DEF', SYSDATE);
TEST_PKG.TEST_PROC( p_num_chef => 2,
p_chef => v_chef_tbl,
p_var1 => v_var1,
p_date => v_date );
dbms_output.put_line('p_var1: ' || v_var1);
dbms_output.put_line('p_date: ' || v_date);
END;
/
R e s u l t :
p_var1: ABC
p_date: 20.11.24
p_var1: DEF
p_date: 21.11.24