我是 PL/SQL 的新手。到现在为止一直很好。我有这个查询,它工作正常。
declare
rec employees_practice%rowtype;
sam taxObligations%rowtype;
socialsecurity number;
rentallowance number;
transportation number;
taxableincome number;
incometaxliability number;
netpay number;
total number;
totaldeductions number;
begin
for rec in (select * from employees_practice)
loop
socialsecurity:=(5.5/100)*(rec.salary);
rentallowance:=(20/100)*(rec.salary);
if(rec.Category='S')
then transportation:= 150;
else transportation:=100;
end if;
taxableincome:=rec.Salary-socialsecurity+rentallowance+transportation;
for sam in (select * from taxObligations)
loop
if(taxableincome between sam.Minincome and sam.Maxincome)
then incometaxliability:= sam.MinimumBracketTax + (taxableincome-sam.Minincome)*(sam.TaxBracketRate/100);
else incometaxliability:=null;
end if;
end loop;
netpay:= taxableincome-incometaxliability;
total:= rec.Salary + rentallowance + transportation;
totaldeductions:=socialsecurity + incometaxliability;
-- Here, I used DBMS.... to give an output in different format.
end loop;
end;
我现在想创建一个包含上述代码的函数,这样我就可以使用单个 SQL 或 PL/SQL 查询来调用它。这让我很头疼。