Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to display custom notification message depending on result of PL/SQL in RESTFul Services

Soukaina IDRISSISep 19 2017 — edited Sep 20 2017

Hi everyone,

After creating this PL/SQL block

BEGIN

  INSERT INTO emp (ename, job) VALUES ( :ename, :job);

COMMIT;

END;

I want to get notification message depending on the result of this INSERT statement, after clicking on submit button.

To do that i tried differents ways :

BEGIN

  INSERT INTO emp (ename, job) VALUES ( :ename, :job);

COMMIT;

--MTH 1: Using output parameter

:o_result := 'Employee created.';

EXCEPTION WHEN OTHERS THEN

:o_result := 'Echec d''insertion - ' || SQLERRM || '.';

END;

BEGIN

  INSERT INTO emp (ename, job) VALUES ( :ename, :job);

COMMIT;

--MTH 2: Using FCT raise_application_error()

  EXCEPTION WHEN OTHERS THEN

    raise_application_error(-20000, 'Echec d''insertion - ' || SQLERRM || '.');

END;

BEGIN

  INSERT INTO emp (ename, job) VALUES ( :ename, :job);

COMMIT;

--MTH 3: Using g_print_success_message

apex_application.g_print_success_message := '<span style="color:green">Employee created.</span>';

EXCEPTION WHEN OTHERS THEN

apex_application.g_print_success_message := '<span style="color:red">No valid fields.</span>';

END;

BEGIN

  INSERT INTO emp (ename, job) VALUES ( :ename, :job);

COMMIT;

--MTH 4: Using APEX_ERROR.ADD_ERROR

EXCEPTION WHEN OTHERS THEN

    APEX_ERROR.ADD_ERROR(

      p_message            =>  'Echec d''insertion - ' || SQLERRM || '.';

      p_display_location   => apex_error.c_inline_in_notification

    );

  

END;

All of this bit of code doesnt works for me.

This post has been answered by Pavel_p on Sep 19 2017
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 17 2017
Added on Sep 19 2017
13 comments
2,522 views