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';

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 ];
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;

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.