title: Fire a trigger before inserting or updating the table, convert into JSON format and post the same on a URL
body: <p>I have a requirement in which I need to update the existing records with new values/insert the new records by converting the data into JSON via Oracle backend(pl/sql). These JSON values need to be posted on URL.I am able to post sample values on the URL via Oracle but before updating/inserting any new values, It throws a mutating error in the trigger when I try to read the table..Can you please post some sample code for this?</p>
  
  <p>Thanks in advance</p>
  
  <pre><code>     CREATE OR REPLACE TRIGGER get_employees_trig before
       INSERT ON emp_table REFERENCING OLD AS OLD NEW AS NEW FOR EACH     
      ROW DECLARE       V_RET VARCHAR2(100);
      BEGIN
      dbms_output.put_line('fired-0');
     IF :NEW.id &lt;&gt;:OLD.id THEN
      V_RET    := post_json_data_fnc(:NEW.id);
      dbms_output.put_line('fired-1');
       END IF;
      dbms_output.put_line('fired-2');
      END;
  
      create or replace FUNCTION post_json_data_fnc(
      p_id IN NUMBER)
      RETURN CLOB
      IS
      req utl_http.req;
      res utl_http.resp;
      url varchar2(200);
      l_clob CLOB;
      l_xml CLOB;
       l_txt CLOB;
  </code></pre>
  
  <p>--content varchar2(4000) := '{"name":"u14", "pass": "123","mail": "user@a.om"}';
          BEGIN</p>
  
  <pre><code>   URL := 'http://10.54.8.210:9200/temp/20';
     l_xml   := json_util_pkg.ref_cursor_to_json (emp_spec.get_employees(p_id));
     req := utl_http.begin_request(URL, 'POST',' HTTP/1.1');
      utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
     utl_http.set_header(req, 'content-type', 'application/json');
     utl_http.set_header(req, 'Content-Length', LENGTH(l_xml));
     l_txt := l_xml;
     utl_http.write_text(req, l_txt);
    res := utl_http.get_response(req);
     utl_http.read_text(res,l_txt);
      UTL_HTTP.END_RESPONSE(res);
      dbms_output.put_line(l_txt);
     return l_txt;
    EXCEPTION
  
    WHEN UTL_HTTP.END_OF_BODY THEN
    UTL_HTTP.END_RESPONSE(res);
     END;
  
  
  
  
        create or replace FUNCTION post_json_data_fnc(
         p_id IN NUMBER)
        RETURN CLOB
         IS
        req utl_http.req;
        res utl_http.resp;
        url varchar2(200);
        l_clob CLOB;
        l_xml CLOB;
        l_txt CLOB;
       BEGIN
  
        URL := 'http';
       l_xml   := json_util_pkg.ref_cursor_to_json (emp_spec.get_employees(p_id));
        req := utl_http.begin_request(URL, 'POST',' HTTP/1.1');
       utl_http.set_header(req, 'user-agent', 'mozilla/4.0');
       utl_http.set_header(req, 'content-type', 'application/json');
       utl_http.set_header(req, 'Content-Length', LENGTH(l_xml));
        l_txt := l_xml;
       utl_http.write_text(req, l_txt);
       res := utl_http.get_response(req);
       utl_http.read_text(res,l_txt);
       UTL_HTTP.END_RESPONSE(res);
      dbms_output.put_line(l_txt);
  
      return l_txt;
       EXCEPTION
  
      WHEN UTL_HTTP.END_OF_BODY THEN
      UTL_HTTP.END_RESPONSE(res);
       END;
  </code></pre>