由于红移功能有限,我经历了真正的挑战。最初,我是将函数用作表类型,以便为我分配的表用作我所负责的jasper报告中的查询。事实证明您不能使用该类型的函数,因为亚马逊仅接受标量值,而不接受多个。有一个SP可以工作,这里的另一个小伙子帮助显示了结果集(下面的代码),但是我仍然需要将整个结果放入表或视图中,以在jasper中传递查询。真是痛苦。我想我只是想检查一下是否有人有想法或曾经在我的鞋里。希望这会在将来对其他人有所帮助。
所提到的不能使用表函数类型,这里不允许使用SP
date_param IN DATE
, result_set INOUT REFCURSOR)
AS $$
BEGIN
OPEN result_set FOR --YTD
SELECT year , month , revenue , transactiondate , Flag
FROM (SELECT EXTRACT(year FROM transactiondate) AS year
, TO_CHAR(transactiondate, 'Mon') AS month
, SUM(netamount) AS revenue
, transactiondate
, Flag
FROM vw_costs_of_businesss_copy
WHERE TO_DATE(transactiondate, 'YYYY-MM-DD') <= date_param
AND TO_DATE(transactiondate, 'YYYY-MM-DD') >= DATE_TRUNC('year',date_param)
GROUP BY year , month , transactiondate , Flag
)
UNION ALL --YTD PREV YEAR
SELECT year ,month ,revenue ,transactiondate ,Flag
FROM (SELECT EXTRACT(year FROM transactiondate) AS year
, TO_CHAR(transactiondate, 'Mon') AS month
, SUM(netamount) AS revenue
, transactiondate
, Flag
FROM vw_costs_of_businesss_copy
WHERE TO_DATE(transactiondate, 'YYYY-MM-DD') <= DATEADD(year, 1, date_param)
AND TO_DATE(transactiondate, 'YYYY-MM-DD') >= DATE_TRUNC('year', DATEADD(year, 1, date_param))
GROUP BY year , month, transactiondate , Flag
)
ORDER BY year
;
RETURN;
END;
$$ LANGUAGE plpgsql;
我只需要尝试封装SP或为视图或表准备一条准备好的语句,SP就可以正常工作,但是Amazon文档在获取准备好的语句方面并不是很详细(至少对于SP而言) )进入表格