我有一个功能,如下所示。我有一个查询字符串,因为我需要使用参数执行它。我的问题是:如何将查询放在“for”中?我试过了
EXECUTE IMMEDIATE query_string
在我的 for 循环中,但它不起作用。
任何人?
问候!
create or replace FUNCTION RO_FUN_TOTAL_SCORE_DATE_PORTAL
(
v_DATE_FIELD IN VARCHAR2
) RETURN RO_OBJ_NESTED_TOTAL_SCORE IS
v_ret RO_OBJ_NESTED_TOTAL_SCORE;
query_string VARCHAR2(1000);
BEGIN
/*Initialize object type to save data*/
v_ret := RO_OBJ_NESTED_TOTAL_SCORE();
query_string := 'SELECT ROUND(AVG(generic_score),2) AS score,
yrp.comment_date_pk AS comment_date,
yrp.hot_id_pk AS hot_id,
yp.portal_id_pk AS portal_id,
AVG(total_opinions) AS total_opinions
FROM yrportalreview yrp JOIN yrhotellinks yrh ON yrp.hot_id_pk =
yrh.hot_id
AND yrp.portal_id_pk = yrh.portal_id AND yrp.comment_date.pk = ' ||
v_DATE_FIELD ||
' WHERE yrp.hot_id_pk IN (92, 27)
AND concept_id_pk = 1
AND yp.active = 1
GROUP BY hot_id_pk,
yp.portal_id_pk,
yrp.comment_date_pk';
FOR I IN (EXECUTE IMMEDIATE query_string)
LOOP
/*insert in table type rows with data*/
v_ret.extend;
v_ret(v_ret.count) := RO_OBJ_TOTAL_SCORE_DATE_PORTAL(i.score,
i.comment_date, i.hot_id, i.portal_id, i.total_opinions);
END LOOP;
RETURN v_ret;
END RO_FUN_TOTAL_SCORE_DATE_PORTAL;