oracle EBS中的PL / SQL函数

时间:2014-03-31 17:27:37

标签: oracle

您好我是oracle Ebs的新手。我遇到了一个pl / sql函数,它正在检查iprocurement中的变量是否带有指定的列表..我不确定如何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;

3 个答案:

答案 0 :(得分:0)

你是别名' Y'当数据行if_it等于1,2或3时为pr.attribute1pr.requisition_header_id = header_id。因此,只要在po.po_requisition_lines pr表格中这两件事情都属实,您就会选择“' Y'”的硬编码值。然后你选择N' N'并将其别名为is_it。因此,如果您传入的header_idpr.requisition_header_id表格中的po.po_requisition_lines pr不匹配,则您的Select Distinct将仅返回N' N'如果您的header_id确实匹配,您将获得“' Y'和' N'。

答案 1 :(得分:0)

该函数返回' N'当且仅当po.po_requisition_lines中的任何记录(其中attribute1在(1,2,3)中)requisition_header_id等于给定参数header_id时。该定义有点过于复杂(可以更简单)。

整个选择返回:

N

Y
N

但后者会引发异常,因为有into子句(它只需要返回单行)。

内部选择:类似,可能有几个带Y的记录。(外部选择使用distinct子句删除重复项。)

答案 2 :(得分:0)

解决方案:

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;