以嵌套 table 作为参数的调用过程
Call procedure with nested table as parameter
如何使用嵌套 table 参数编写程序代码?在 table 测试中,我需要从循环中插入数据,例如。 1,2,3...
plsql
Declare
TYPE code_nt is table of varchar2(10);
l_codes code_nt := code_nt();
begin
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
l_codes.extend;
l_codes(i) := to_char(i);
END LOOP;
//here call procedure
//PKG_EMP.INSERT_EMP(PAR_1);
end;
包:
create or replace PACKAGE PKG_EMP AS
TYPE code_nt is table of varchar2(10);
l_codes code_nt := code_nt();
procedure INSERT_EMP (PAR_1 code_nt);
END;
create or replace PACKAGE BODY PKG_EMP AS
procedure INSERT_EMP (PAR_1 code_nt) AS
BEGIN
INSERT INTO test (ID) VALUES (value from code_nt);
END;
end;
您的代码将不起作用,因为 code_nt
是您的 PL/SQL 函数和 PL/SQL 匿名块中的本地定义类型,尽管名称和签名相同,但它们是不同的数据类型。
您需要在两者中使用相同的数据类型:
Declare
l_codes PKG_EMP.code_nt := PKG_EMP.code_nt();
begin
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
l_codes.extend;
l_codes(i) := to_char(i);
-- or
-- l_codes(i) := TO_CHAR( APEX_APPLICATION.G_F01(i) );
END LOOP;
PKG_EMP.INSERT_EMP(l_codes);
END;
/
您可以将包裹声明为:
CREATE PACKAGE PKG_EMP AS
TYPE code_nt is table of varchar2(10);
PROCEDURE INSERT_EMP (PAR_1 code_nt);
END;
/
CREATE PACKAGE BODY PKG_EMP AS
procedure INSERT_EMP (PAR_1 code_nt) AS
BEGIN
FORALL i IN 1 .. par_1.COUNT
INSERT INTO test (ID) VALUES ( par_1(i) );
END;
END;
/
db<>fiddle here
如何使用嵌套 table 参数编写程序代码?在 table 测试中,我需要从循环中插入数据,例如。 1,2,3...
plsql
Declare
TYPE code_nt is table of varchar2(10);
l_codes code_nt := code_nt();
begin
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
l_codes.extend;
l_codes(i) := to_char(i);
END LOOP;
//here call procedure
//PKG_EMP.INSERT_EMP(PAR_1);
end;
包:
create or replace PACKAGE PKG_EMP AS
TYPE code_nt is table of varchar2(10);
l_codes code_nt := code_nt();
procedure INSERT_EMP (PAR_1 code_nt);
END;
create or replace PACKAGE BODY PKG_EMP AS
procedure INSERT_EMP (PAR_1 code_nt) AS
BEGIN
INSERT INTO test (ID) VALUES (value from code_nt);
END;
end;
您的代码将不起作用,因为 code_nt
是您的 PL/SQL 函数和 PL/SQL 匿名块中的本地定义类型,尽管名称和签名相同,但它们是不同的数据类型。
您需要在两者中使用相同的数据类型:
Declare
l_codes PKG_EMP.code_nt := PKG_EMP.code_nt();
begin
FOR i IN 1..APEX_APPLICATION.G_F01.COUNT LOOP
l_codes.extend;
l_codes(i) := to_char(i);
-- or
-- l_codes(i) := TO_CHAR( APEX_APPLICATION.G_F01(i) );
END LOOP;
PKG_EMP.INSERT_EMP(l_codes);
END;
/
您可以将包裹声明为:
CREATE PACKAGE PKG_EMP AS
TYPE code_nt is table of varchar2(10);
PROCEDURE INSERT_EMP (PAR_1 code_nt);
END;
/
CREATE PACKAGE BODY PKG_EMP AS
procedure INSERT_EMP (PAR_1 code_nt) AS
BEGIN
FORALL i IN 1 .. par_1.COUNT
INSERT INTO test (ID) VALUES ( par_1(i) );
END;
END;
/
db<>fiddle here