0

I am trying to execute this function but it is giving me error

ERROR: syntax error at or near "return"
LINE 12: return;

what's wrong with this line ?? I am using Postgres(9.2).

create or replace function conditional_tax(taxPerc decimal(5),minSal decimal(5)) returns SETOF emp as
$body$
declare r emp%rowtype;
begin
 For r in select * from emp where salary > minSal
 Loop
 r.salary = r.salary - (r.salary * taxPerc /100) ;
 return next r;
 End Loop
 return;
end
$body$
Language 'plpgsql';
asked Sep 13, 2013 at 4:00

2 Answers 2

1

There's nothing wrong with that line. However, there is something wrong with the previous line.

You're meant to terminate the end loop with a semi-colon ;. The syntax chart is:

[ <<label>> ]
LOOP
 statements
END LOOP [ label ];
answered Sep 13, 2013 at 4:09
Sign up to request clarification or add additional context in comments.

Comments

1

This is much simpler. Just plain SQL. SQL Fiddle

create or replace function conditional_tax(
 taxPerc decimal(5),
 minSal decimal(5)
) returns SETOF decimal(5) as $body$
select salary * (1 - taxPerc / 100) as salary
from emp
where salary > minSal
;
$body$ language sql;
answered Sep 14, 2013 at 12:00

Comments

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.