Skip to Main Content

ORDS, SODA & JSON in the Database

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 post/update stuff with ORDS 3.0 with the package ORDS_SERVICES

Careau-OracleSep 17 2015 — edited Sep 18 2015

Hi

I'm creating a rest api using ORDS 3.0 and the package ORDS_SERVICES. ORDS is deployed in Weblogic 12c. (Not using APEX)

I'm able to make GET calls to retreive JSON objects but when I try to make a POST method to update or process something in the database, it does not work.

I get an 500 internal server error.

I can't find any example on the web or any good documentation about the package.

What am I doing wrong ?

Here's my code.

I passed a json object like this

{"empno": 7369,"ename":"SMITH44","job":"clerk","mgr":7902,"hiredate":"1980-12-17T05:00:00Z","sal":800,"comm":null, "deptno":20}

declare

  l_moduleId number;

  l_templateId number;

  l_handlerId  number;

  l_parameterId number;

begin

    ords_services.delete_module(p_name => 'emp_module');

    l_moduleId := ORDS_SERVICES.create_module(p_name => 'emp_module',

                                               p_uri_prefix => '/emp_module',

                                               p_items_per_page => 10,

                                               p_status => 'PUBLISHED',

                                               p_comments => 'Comments on Module emp_module');

    l_templateId := ORDS_SERVICES.add_template(p_module_id => l_moduleId,

                                               p_uri_template => '/postemp/',

                                               p_priority => 0,

                                               p_etag_type => 'HASH',

                                               p_etag_query => null,

                                               p_comments => 'POST emp emp/');

    l_handlerId := ORDS_SERVICES.add_handler(p_template_id => l_templateId,

                                              p_source_type =>  'plsql/block',

                                              p_method => 'POST',

                                              p_items_per_page => null,

                                              p_mimes_allowed =>null,

                                              p_comments => 'Comments on handler ',

                                              p_source => 'declare

  lCount number;

begin

    select count(1)

    into lCount

    from emp where empno = 73369;

  if lCount=0 then

    insert into emp3 (empno, ename, job, mgr, hiredate, sal, comm, deptno)

             values  (:empno, :ename, :job, :mgr, :hiredate, :sal, :comm, :deptno);

  else

    update  emp3

       set empno = :empno,

           ename = :ename,

           job = :job,

           mgr = :mrg,

           hiredate = :hiredate,

           sal = :sal,

           comm = :comm,

           deptno = :deptno)

     where empno = :empno;

  end if;

  /*:status := 201;*/

end;');


end;

This post has been answered by Kiran Pawar on Sep 18 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Oct 16 2015
Added on Sep 17 2015
1 comment
655 views