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.

Old programming trick. Take the code in some edited and delete all characters but the parens. If it is a parens issue, you'll see it quickly.

Also, in the editor count how many left then right parens there are. Should be equal.

commented: Tried with that way, parens are equal but same problem +0
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.