从过程中调用 table 函数 (pl sql)
Calling table function from procedure (pl sql)
我在从我的过程中调用 returns 一个 table 的函数时遇到了很大的麻烦。我认为我的声明有问题,因此无法编译。这是我的代码.. 开发人员用红色下划线 SELECT "D_ID" 和 from table "(IREL_FN (X))"; 。这是我的代码。
CREATE OR replace PROCEDURE Irrelevant_skata (x NUMBER)
AS
d_id T_ID_TABLE;
BEGIN
DECLARE
TYPE yo_table
IS
TABLE OF YO_TABLE;
YO_TABLE "(IREL_FN (X))"%TYPE;
id NUMBER;
BEGIN
SELECT "D_ID"
INTO yo_table
FROM TABLE "(IREL_FN (X))";
EXCEPTION
WHEN no_data_found THEN
dbms_output.Put_line('NO DATA FOUND');
END;
END irrelevant_skata;
和函数
CREATE OR replace FUNCTION Irel_fn (x IN NUMBER)
RETURN T_ID_TABLE
AS
id T_ID_TABLE;
BEGIN
BEGIN
SELECT Cast(MULTISET(SELECT "id"
FROM "somethingcopy"
WHERE "kati" IN (SELECT "auto"
FROM "ekeino"
WHERE "id" = x)) AS T_ID_TABLE)
INTO id
FROM dual;
RETURN id;
EXCEPTION
WHEN no_data_found THEN
dbms_output.Put_line('null');
END;
END irel_fn;
如果不知道您要做什么,很难回答。
YO_TABLE "(IREL_FN (X))"%TYPE;
这没有任何意义。您不能将变量声明为函数的 %type
。抬头看YO_TABLE声明,你写
DECLARE
TYPE yo_table
IS
TABLE OF YO_TABLE;
嗯? table 声明是 table 您正在声明的同一变量?
还有这个:
SELECT "D_ID"
INTO yo_table
FROM TABLE "(IREL_FN (X))";
转table时不需要引号,IREL_FN(X)中的x
是形参,需要换成实际值what你需要通过
我正在回答你标记为重复的问题(精确提取的问题)。
我按以下方式重写了您的代码,希望对您有所帮助。我将 Irel_fn 设为流水线函数,但是如果您愿意,您仍然可以编写 Cast multiset ,但是您还需要使用类型构造函数。
create table auto(id number)
这个 table 不是你的源代码 "AUTO"(所以我可以编译它)。
create or replace type t_id as object (id number);
/
Create or replace type t_id_table is table of t_id;
/
create or replace FUNCTION Irel_fn (x IN NUMBER) RETURN T_ID_TABLE PIPELINED
as
BEGIN
for rec in (select id from auto where id=x)
loop
Pipe row (t_id(rec.id));
end loop;
return;
end;
/
create or replace procedure Irrelevant_skata (insid in NUMBER) is
bob t_id_table;
BEGIN
select t_id(id) bulk collect into bob from table(irel_fn(insid));
END;
create or replace
PROCEDURE IRRELEVANT_SKATA (INSID IN NUMBER) AS ID T_ID_TABLE ;
BEGIN
DECLARE
YO_TABLE T_ID_TABLE;
BEGIN
select ID
into YO_TABLE
from table(IREL_FN(INSID));
EXCEPTION
WHEN NO_DATA_FOUND THEN dbms_output.put_line('NO DATA FOUND');
END;
END IRRELEVANT_TWEET;
<-----------------------------FUNCTION---------------------------------->
create or replace
FUNCTION IREL_FN ( D_ID IN NUMBER ) RETURN T_ID_TABLE AS
ID T_ID_TABLE;
BEGIN
BEGIN
SELECT CAST(
MULTISET(
SELECT "Id"
FROM "SOMETHINGCOPY"
WHERE "KATI" = (SELECT "EKEINO" FROM "AUTO" WHERE "Id"=D_ID)
INTO ID
FROM DUAL;
return ID;
EXCEPTION
WHEN NO_DATA_FOUND THEN dbms_output.put_line('null');
END;
END IREL_FN;
希望对您有所帮助:)
我在从我的过程中调用 returns 一个 table 的函数时遇到了很大的麻烦。我认为我的声明有问题,因此无法编译。这是我的代码.. 开发人员用红色下划线 SELECT "D_ID" 和 from table "(IREL_FN (X))"; 。这是我的代码。
CREATE OR replace PROCEDURE Irrelevant_skata (x NUMBER)
AS
d_id T_ID_TABLE;
BEGIN
DECLARE
TYPE yo_table
IS
TABLE OF YO_TABLE;
YO_TABLE "(IREL_FN (X))"%TYPE;
id NUMBER;
BEGIN
SELECT "D_ID"
INTO yo_table
FROM TABLE "(IREL_FN (X))";
EXCEPTION
WHEN no_data_found THEN
dbms_output.Put_line('NO DATA FOUND');
END;
END irrelevant_skata;
和函数
CREATE OR replace FUNCTION Irel_fn (x IN NUMBER)
RETURN T_ID_TABLE
AS
id T_ID_TABLE;
BEGIN
BEGIN
SELECT Cast(MULTISET(SELECT "id"
FROM "somethingcopy"
WHERE "kati" IN (SELECT "auto"
FROM "ekeino"
WHERE "id" = x)) AS T_ID_TABLE)
INTO id
FROM dual;
RETURN id;
EXCEPTION
WHEN no_data_found THEN
dbms_output.Put_line('null');
END;
END irel_fn;
如果不知道您要做什么,很难回答。
YO_TABLE "(IREL_FN (X))"%TYPE;
这没有任何意义。您不能将变量声明为函数的 %type
。抬头看YO_TABLE声明,你写
DECLARE
TYPE yo_table
IS
TABLE OF YO_TABLE;
嗯? table 声明是 table 您正在声明的同一变量?
还有这个:
SELECT "D_ID"
INTO yo_table
FROM TABLE "(IREL_FN (X))";
转table时不需要引号,IREL_FN(X)中的x
是形参,需要换成实际值what你需要通过
我正在回答你标记为重复的问题(精确提取的问题)。 我按以下方式重写了您的代码,希望对您有所帮助。我将 Irel_fn 设为流水线函数,但是如果您愿意,您仍然可以编写 Cast multiset ,但是您还需要使用类型构造函数。
create table auto(id number)
这个 table 不是你的源代码 "AUTO"(所以我可以编译它)。
create or replace type t_id as object (id number);
/
Create or replace type t_id_table is table of t_id;
/
create or replace FUNCTION Irel_fn (x IN NUMBER) RETURN T_ID_TABLE PIPELINED
as
BEGIN
for rec in (select id from auto where id=x)
loop
Pipe row (t_id(rec.id));
end loop;
return;
end;
/
create or replace procedure Irrelevant_skata (insid in NUMBER) is
bob t_id_table;
BEGIN
select t_id(id) bulk collect into bob from table(irel_fn(insid));
END;
create or replace
PROCEDURE IRRELEVANT_SKATA (INSID IN NUMBER) AS ID T_ID_TABLE ;
BEGIN
DECLARE
YO_TABLE T_ID_TABLE;
BEGIN
select ID
into YO_TABLE
from table(IREL_FN(INSID));
EXCEPTION
WHEN NO_DATA_FOUND THEN dbms_output.put_line('NO DATA FOUND');
END;
END IRRELEVANT_TWEET;
<-----------------------------FUNCTION---------------------------------->
create or replace
FUNCTION IREL_FN ( D_ID IN NUMBER ) RETURN T_ID_TABLE AS
ID T_ID_TABLE;
BEGIN
BEGIN
SELECT CAST(
MULTISET(
SELECT "Id"
FROM "SOMETHINGCOPY"
WHERE "KATI" = (SELECT "EKEINO" FROM "AUTO" WHERE "Id"=D_ID)
INTO ID
FROM DUAL;
return ID;
EXCEPTION
WHEN NO_DATA_FOUND THEN dbms_output.put_line('null');
END;
END IREL_FN;
希望对您有所帮助:)