WITH SELECTの結果をネストされた配列(2つの属性を持つ)に挿入するにはどうすればよいですか?
DDLおよびDMLSQLは次のとおりです。
NUMBER(8)について心配する必要はありません
CREATE OR REPLACE TYPE DATE_RANGE IS OBJECT ( start_date NUMBER( 8 ), end_date NUMBER( 8 ) );
CREATE OR REPLACE TYPE DATE_RANGE_ARR IS TABLE OF DATE_RANGE;
DECLARE
g_splited_range_arr DATE_RANGE_ARR := DATE_RANGE_ARR( );
g_travel_range DATE_RANGE := DATE_RANGE( '20110101', '99991231' );
g_bo_arr DATE_RANGE_ARR := DATE_RANGE_ARR( DATE_RANGE( '20110312', '20110317' ), DATE_RANGE( '20110315', '20110329' ) );
FUNCTION split_date_sql( pr_travel_date_range DATE_RANGE,
pr_bo_arr DATE_RANGE_ARR )
RETURN DATE_RANGE_ARR
IS
l_splited_range_arr DATE_RANGE_ARR;
BEGIN
SELECT start_date, end_date
INTO l_splited_range_arr(start_date, end_date)
FROM (WITH all_dates
AS (SELECT tr_start_date AS a_date, 0 AS black_out_val FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT tr_end_date, 0 FROM TABLE( pr_travel_date_range )
UNION ALL
SELECT bo_start_date - 1, 1 FROM TABLE( pr_bo_arr )
UNION ALL
SELECT bo_end_date + 1, -1 FROM TABLE( pr_bo_arr )),
got_analytics
AS (SELECT a_date AS start_date,
LEAD( a_date ) OVER (ORDER BY a_date, black_out_val) AS end_date,
SUM( black_out_val ) OVER (ORDER BY a_date, black_out_val) AS black_out_cnt
FROM all_dates)
SELECT start_date, end_date
FROM got_analytics
WHERE black_out_cnt = 0 AND start_date < end_date
ORDER BY start_date);
RETURN l_splited_range_arr;
END;
BEGIN
g_splited_range_arr := split_date_sql(g_travel_range,g_bo_arr);
FOR index_g_splited_range_arr IN g_splited_range_arr .FIRST .. g_splited_range_arr .LAST LOOP
DBMS_OUTPUT.PUT_LINE('g_splited_range_arr[' || index_g_splited_range_arr || ']: ' || g_splited_range_arr(index_g_splited_range_arr).start_date || '-' || g_splited_range_arr(index_g_splited_range_arr).end_date );
END LOOP;
EXCEPTION
WHEN NO_DATA_FOUND
THEN
NULL;
WHEN OTHERS
THEN
NULL;
END;
または、ネストされた配列のパラメーターを含むVIEWを作成して、単純に呼び出すことができますか?
SELECT *
BULK COLLECT INTO g_splited_range_arr
FROM view_split_date(g_travel_range,g_bo_arr);