I have problems with opening cursor with string variable
here is my oracle database code
FUNCTION f_get_cursor(p_date_to_forecast VARCHAR) RETURN SYS_REFCURSOR AS
v_cursor SYS_REFCURSOR;
v_groupby_stmt VARCHAR(200) := 'GROUP BY '
|| CASE WHEN p_date_to_forecast = 'HOLIDAY' THEN
'DAY, ' ELSE '' END
|| 'TNI, FRMP, LR, HH;';
v_select_stmt VARCHAR2(1000) := 'SELECT WEEKDAY, TNI, FRMP, LR, HH,
AVG(Coalesce(VOLUME, 0)) AS AverageVolume
FROM (SELECT v.TNI, v.FRMP, v.LR, v.DAY,
v.HH, v.VOLUME, CASE WHEN
hd.HOLIDAY_DATE is not null
then ''HOLIDAY''
ELSE trim(to_char(v.DAY, ''Day''))
END AS WEEKDAY
FROM v_nem_rm16 v
LEFT JOIN DBP_ADMIN.DBP_HOLIDAY hd
ON v.DAY = hd.HOLIDAY_DATE
WHERE v.STATEMENT_TYPE !=''FORCAST'')
WHERE WEEKDAY = ''' || p_date_to_forecast
|| '''' || ' ' || v_groupby_stmt;
BEGIN
OPEN v_cursor FOR v_select_stmt;
return v_cursor;
END;
I am just trying to open cursor based on the parameter "p_date_to_forcast", which is just string of the name of the week like "Saturday, Tuesday..and so on" and return the cursor.
When I run the query, I got this error
00911. 00000 - "invalid character"
*Cause: identifiers may not start with any ASCII character other than
letters and numbers. $#_ are also allowed after the first
character. Identifiers enclosed by doublequotes may contain
any character other than a doublequote. Alternative quotes
(q'#...#') cannot use spaces, tabs, or carriage returns as
delimiters. For all other contexts, consult the SQL Language
Reference Manual.
*Action:
What is the problem and How can I fix it???
thanks