1 回答
TA贡献1853条经验 获得超9个赞
以下函数返回给定 PROJECT_ID 和 TYPE 的下一个 ATA 编号。
create or replace function get_ata_number (
p_project_id in number
,p_type in number
) return number as
l_NextNumber number;
begin
if p_type = 1 then
SELECT SUM(NextNumber) + 1
into l_NextNumber
FROM (
SELECT COUNT(a1.ATAID) AS NextNumber
FROM ata AS a1
WHERE a1.ProjectID = p_project_id
AND a1.Ata = 1
AND a1.ParentAta = 0
AND a1.TYPE = 1
AND a1.BecomeExternalAtaFromInternal = 0
UNION ALL
SELECT COUNT(a2.ATAID) AS NextNumber
FROM ata AS a2
WHERE a2.ProjectID = p_project_id
AND a2.Ata = 1
AND a2.ParentAta = 0
AND a2.BecomeExternalAtaFromInternal = 1 );
else
SELECT COUNT(ata.ATAID) + 1
into l_NextNumber
FROM ata
WHERE ProjectID = p_project_id
AND Ata = 1
AND ParentAta = 0
AND Type = 0 ;
end if;
return l_NextNumber;
end get_ata_number;
请注意我对 PROJECT_ID 数据类型的假设,并在必要时更正它。
- 1 回答
- 0 关注
- 67 浏览
添加回答
举报