I'm writing stored procedure with dynamic sql having dynamic table name as,
CREATE OR replace PROCEDURE Pr_get_result (p_table_name IN VARCHAR2, p_object_Id IN VARCHAR2)
IS
p_prop_code VARCHAR2(50) := 'pH';
BEGIN
EXECUTE IMMEDIATE
'DECLARE ' ||
' TYPE ObjCurTyp IS REF CURSOR; ' ||
' v_obj_cursor ObjCurTyp; ' ||
' v_stmt_str VARCHAR2(32000); ' ||
' v_obj_record ' || p_table_name || '%rowtype; '||
'BEGIN ' ||
' v_stmt_str := ''SELECT * FROM ( SELECT * FROM '|| p_table_name ||' where CREATED_DATE<= ( SELECT CREATED_DATE FROM '|| p_table_name ||' WHERE object_id='|| p_object_Id ||' AND PROPERTY_CODE='|| p_prop_code || ' ) Order By CREATED_DATE DESC ) WHERE ROWNUM <= 5''; ' ||
' OPEN v_obj_cursor ' ||
' FOR v_stmt_str ; ' ||
' LOOP ' ||
' FETCH v_obj_cursor INTO v_obj_record; ' ||
' EXIT WHEN v_obj_cursor %NOTFOUND; ' ||
' END LOOP; ' ||
'END;';
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
And getting above problem. Could you please help to resolve this.