설문조사
PostgreSQL/PPAS 관련 듣고 싶은 교육은


총 게시물 187건, 최근 0 건
   

조건문을 추가 할려니 오류가 발생됩니다.

글쓴이 : 호야 날짜 : 2014-12-19 (금) 14:47 조회 : 12036
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.
이런 오류가 발생이 되구요.
제가 뭘 잘못하고 있는지 모르겠습니다.

다시 한번더 답변을 부탁드리겠습니다.
감사합니다.

PostgresDBA 2014-12-19 (금) 18:13
댓글주소
호야 2014-12-22 (월) 10:31
빠른 답변 감사드립니다.
postgresql 쉬운것 같으면서도 너무 어렵네요..
다시 한번더 답변에 감사드립니다.
댓글주소
   

postgresdba.com