create or replace function foo(IN _empno integer, out ename text, out job text)
returns setof record as
$$
if _empno = 1 then
_empno := 100;
end if;
select ename, job from emp where empno=_empno;
$$
LANGUAGE SQL;
이렇게 if문을 추가 하고 함수를 생성할려고 하면
ERROR: syntax error at or near "if"
SQL state: 42601
오류가 발생됩니다.
create or replace function foo(IN _empno integer, out ename text, out job text)
returns setof record as
$$
begin
if _empno = 1 then
_empno := 100;
end if;
select ename, job from emp where empno=_empno;
end;
$$
LANGUAGE plpgsql;
이렇게 함수를 만들면 생성은 되는데 실행을 하면
ERROR: query has no destination for result data
SQL state: 42601
Hint: If you want to discard the results of a SELECT, use PERFORM instead.
이런 오류가 발생이 되구요.
제가 뭘 잘못하고 있는지 모르겠습니다.
다시 한번더 답변을 부탁드리겠습니다.
감사합니다.
|