我有一个在Toad for Oracle(或PL/SQL Developer)中运行的脚本:
select distinct AC.STATUS, S.DESCRIPTION, count(*) || ' / ' || (
select count(*)
from ACC AC
where AC.STATUS is not null
) "Count"
from ACC AC
join ACC_STATUS S
on AC.STATUS = S.STATUS
group by AC.STATUS, S.DESCRIPTION
order by AC.STATUS;
所以它的表现相当不错,向我展示了如下结果:
-7 Status 1 30 / 174
-6 Status 2 124 / 174
-3 Status 3 6 / 174
-2 Status 4 4 / 174
-1 Status 5 10 / 174
我想重构这段代码,并将第一个选择器(括号内的)提取到一个函数中,类似于:
declare function zz
return number
is
declare res number;
begin
select count(*) into res
from ACC AC
where AC.STATUS is not null;
return res;
end zz;
然后在脚本中以某种方式使用它。
这可行吗?我需要使用哪种语法?我不想将函数保存到数据库中 - 只想在Toad或PL/SQL Developer中为自己的需求运行它。(我们有Oracle版本12.1.0.2.0。)