CREATE OR REPLACE FUNCTION fc_book_jego(character varying, timestamp with time zone, timestamp with time zone)
RETURNS SETOF record AS
$BODY$
DECLARE
r re;
BEGIN
select re.mid, re.mcode, re.trcode, re.mulcode,
re.icnt, re.ocnt, re.scnt
From
(
-- t_in Table의 입고.
Select a.mid, a.mcode, a.trcode, a.mulcode,
Sum( a.cnt )As icnt, 0 As ocnt, 0 As scnt
From t_in a
Where a.mid = $1
And a.save_day BetWeen $2 And $3
Group By a.mid, a.mcode, a.trcode, a.mulcode
Union All
-- t_out Table의 입고.
Select a.mid, a.mcode, a.trcode, a.mulcode,
Sum( a.cnt )As icnt, 0 As ocnt, 0 As scnt
From t_out a Left Outer Join t_trade b On b.mid = a.mid And b.trcode = a.mcode
Left Outer Join t_trade c On c.mid = a.mid And c.trcode = a.trcode
Left Outer Join t_mulpum d On d.mid = a.mid And d.mulcode = a.mulcode
Where a.mid = $1
And a.save_day BetWeen $2 And $3
Group By a.mid, a.mcode, a.trcode, a.mulcode
)re;
END;$BODY$
LANGUAGE sql VOLATILE
COST 100;
ALTER FUNCTION fc_book_jego(character varying, timestamp without time zone, timestamp without time zone) OWNER TO postgres;
이렇게 하니까,
ERROR: syntax error at or near "re"
LINE 5: r re;
^
********** Error **********
ERROR: syntax error at or near "re"
SQL state: 42601
Character: 156
이런 에러가 나네요.
조회한 모든 컬럼을 다 리턴해야되는데, 어떻게 해야되나요..
|