我正在尝试创建一个具有以下功能的"item_list function"
:
TRUNC(SYSDATE) + 1
指定为pv_end_date
参数的DEFAULT值。item_rec
记录类型。item_cur
系统引用游标。item_row
变量。item_set
变量,并创建item_tab集合的空实例。将NDS字符串分配给stmt变量。该字符串应返回以下列:
item_title
,别名为title
item_subtitle
,别名为subtitle
item_rating
,别名为rating
item_release_date
,别名为release_date
并且WHERE
子句应该检查MPAA的item_rating_agency
值和item_release_date
之间的值{/ 1}}
pv_start_date
和pv_end_date
值的变量
pv_start_date
子句中分配pv_end_date
和USING
个变量。item_cur
系统引用光标提取到item_row
数据类型的item_rec
变量中。item_set
集合的item_tab
变量中扩展空间。item_row
变量创建item_set
集合的实例。我已经创建了item_obj
和item_tab
以下是我需要帮助的部分:
--create a item_list function
CREATE OR REPLACE
FUNCTION item_list
( pv_start_date DATE
, pv_end_date DATE )
RETURN item_tab IS
/* Declare a record type. */
TYPE item_rec IS RECORD
( title VARCHAR2(60)
, subtitle VARCHAR2(60)
, rating VARCHAR2(8)
, release_date DATE);
/* Declare reference cursor for an NDS cursor. */
item_cur SYS_REFCURSOR;
/* Declare a customer row for output from an NDS cursor. */
item_row ITEM_REC;
item_set ITEM_TAB := item_tab();
/* Declare dynamic statement. */
stmt VARCHAR2(2000);
BEGIN
/* Create a dynamic statement. */
stmt := SELECT 'title, rating'|| FROM 'item '|| WHERE 'REGEXP_LIKE(release_date,''^.*''||:input||''.*$'')';
/* Open and read dynamic cursor. */
OPEN item_cur FOR stmt USING pv_start_date AND pv_end_date;
LOOP
/* Fetch the cursror into a customer row. */
FETCH item_cur INTO item_row;
EXIT WHEN item_cur%NOTFOUND;
/* Extend space and assign a value collection. */
item_set.EXTEND;
item_set(item_set.COUNT) :=
item_obj ( item_title => item_title.title
, item_subtitle => item_subtitle.subtitle
, item_rating => item_rating.rating
, item_release_date => item_release_date.release_date );
END LOOP;
/* Return customer set. */
RETURN item_set;
END item_list;
/
--call the customer_list function
desc item_list