[代码]
CREATE OR REPLACE FUNCTION
DWH_PRODUCTION_SUM_QTDYTD(V_TBL_NAME IN VARCHAR2,V_COL_NAM IN VARCHAR2,V_RPRT_DATE VARCHAR2,
V_FLTRCOL IN VARCHAR2,VALUE_OF IN VARCHAR2, V_GROUP_COL VARCHAR2,V_DF_COL VARCHAR2)-----
RETURN NUMBER IS
A_RET_VALUE NUMBER;
V_REPORT_DATE DATE:=V_RPRT_DATE;
V_FILTERCOL VARCHAR2(30):=UPPER(V_FLTRCOL);
V_COL_NAME VARCHAR2(30):=UPPER(V_COL_NAM);
V_TAB_NAME VARCHAR2(30):=UPPER(V_TBL_NAME);
V_VALUE_TYPE VARCHAR2(8):=UPPER(VALUE_OF);
V_GRP_COL VARCHAR2(30):=UPPER(V_GROUP_COL);
V_DIFF_COL VARCHAR2(30):=UPPER(V_DF_COL);
V_QUARTER_NUMBER NUMBER(1);
V_QTY VARCHAR2(1000);
V_CURRQTD_STRT VARCHAR2(11);
V_CURRQTD_END VARCHAR2(11);
V_CURRQTD VARCHAR2(1000);
BEGIN
--------------------GETTING QUARTER NO.------------------------------
V_QTY:='SELECT TO_NUMBER(TO_CHAR(TO_DATE('''||V_REPORT_DATE||'''), ''Q'')) FROM DUAL';
--DBMS_OUTPUT.PUT_LINE(V_QTY);
EXECUTE IMMEDIATE V_QTY INTO V_QUARTER_NUMBER ;
--DBMS_OUTPUT.PUT_LINE('QT NUM'||V_QUARTER_NUMBER);
--------------------CURRENT QUARTER VALUE------------------------------
SELECT MIN (t)"CURNT_QTR_ST_DT", MAX (LAST_DAY (t))"CURNT_QTR_END_DT", ADD_MONTHS(MIN (t),-
3)"PREV_QTR_ST_DT", ADD_MONTHS(MAX (LAST_DAY (t)),-3) "PREV_QTR_END_DT" INTO FROM (SELECT
V_CURRQTD_STRT ,V_CURRQTD_END,V_PRVQTD_STRT, V_PRVQTD_END
ADD_MONTHS (TRUNC(TO_DATE(TO_DATE(V_REPORT_DATE)), 'YYYY'), LEVEL - 1) t,
TO_CHAR (ADD_MONTHS (TRUNC(TO_DATE(TO_DATE(V_REPORT_DATE)), 'YYYY'), LEVEL - 1), 'Q')QTD
FROM DUAL
CONNECT BY LEVEL <= 12) A
WHERE A.QTD = V_QUARTER_NUMBER;
V_CURRQTD:='SELECT '||V_GRP_COL||', '||V_DIFF_COL||', SUM('||V_COL_NAME||') AND TO_DATE------- ------here m calculating the values dynamically
FROM '||V_TAB_NAME|| ' WHERE '||V_FILTERCOL||' BETWEEN TO_DATE('''||V_CURRQTD_STRT||''') '
|| ' ('''||V_REPORT_DATE||''') GROUP BY '||V_GRP_COL||','||V_DIFF_COL||'';
--V_CURRQTD:= V_CURRQTD ||' GROUP BY '||V_GRP_COL;
--DBMS_OUTPUT.PUT_LINE(V_CURRQTD);
--EXECUTE IMMEDIATE V_CURRQTD INTO V_SUM;
EXECUTE IMMEDIATE V_CURRQTD BULK COLLECT INTO CRQNUMS,CRQNUMS1,CRQNUMS2;
FOR I IN CRQNUMS.FIRST .. CRQNUMS.LAST LOOP
DBMS_OUTPUT.PUT_LINE (
' ITEM_CODE'' ' || CRQNUMS(I) || ': ' || CRQNUMS1(I)
|| ': ' || CRQNUMS2(I));
END LOOP;[/code]
这我需要在表函数中实现....在上面的查询中,m 从第一个 qry 获取 qtr no,然后在第二个获取 qtr 的第一个和最后一个日期...之后 m 动态地将值填充到枚举中。 ... enums2 使用批量收集,但无法以表格形式获取输出...。
我已经实现了这个并获得了正确的值,但需要在表函数中实现以获取 tablur 形式的输出