您好,我是oracle Ebs的新手。我遇到了一个pl/sql函数,它可以检查i采购中的变量是否符合指定的列表。我不确定SELECT 'Y'
是如何编写的。
function if_it (header_id NUMBER) RETURN CHAR IS
x_it CHAR(1);
begin
SELECT DISTINCT if_it
into x_it
FROM (
SELECT 'Y' if_it
FROM po.po_requisition_lines pr
where nvl(to_number(pr.attribute1), 0) IN (1,2,3)
and pr.requisition_header_id = header_id
UNION
SELECT 'N' is_it FROM DUAL);
return x_it;
exception when others then -- returned Yes and No, so we want to retyurn Yes
return 'Y';
end if_it;
发布于 2014-04-01 05:25:11
当数据pr.attribute1
行等于1、2或3时,您将'Y‘别名为if_it
。并且pr.requisition_header_id = header_id
。因此,每当在po.po_requisition_lines pr
表中这两件事为真时,您就选择了一个硬编码值'Y‘。然后选择'N‘并将其别名为is_it
。因此,如果您传入的header_id
与po.po_requisition_lines pr
表中的pr.requisition_header_id
不匹配,那么您的Select Distinct
将只返回'N‘。如果你的header_id
确实匹配,你会得到一个'Y‘和'N’。
发布于 2014-04-01 06:00:20
当且仅当attribute1在(1,2,3)中的po.po_requisition_lines中没有记录的requisition_header_id等于给定参数header_id时,该函数才返回'N‘。定义有点过于复杂(可以更简单)。
整个select返回以下两种结果之一:
N
或
Y
N
但后者会引发异常,因为有into
子句(它只希望返回单行)。
内部select: similar,只是可能有几条记录使用Y。(外部select使用distinct
子句删除重复项)。
发布于 2017-07-20 03:25:51
解决方案:
function if_it (p_header_id NUMBER) RETURN VARCHAR2 IS
begin
FOR cur IN (SELECT NULL FROM DUAL
WHERE EXISTS
(SELECT NULL
FROM po.po_requisition_lines pr
where nvl(to_number(pr.attribute1), 0) IN (1,2,3)
and pr.requisition_header_id = p_header_id)
) LOOP
RETURN 'Y';
END LOOP;
RETURN 'N';
end if_it;
https://stackoverflow.com/questions/22768229
复制相似问题