Hi everbady,
i have created the modele "hr.exemple.service"
and URI TEMPLET: "employees/:id"
mathod GET with SQL: select * from empwhere empno = :id or :id is null
mathod POST with SQL: declare
l_new_id number;
begin
insert into emp(empno,ename,job,mgr,hiredate,sal,comm,deptno)
values
(:empno,:ename,:job,:mgr,:hiredate,:sal,:comm,:deptno);
:status := 201; --created
exception when others then
:status := 400; --error
:errmsg := sqlerrm;
end;
mathod PUS with SQL: begin
if :id is not null then
for i in(select * from emp where empno = :id) loop
update emp
set ename = nvl(:ename,i.ename),
job = nvl(:job,i.job),
mgr = nvl(:mgr,i.mgr),
hiredate = nvl(:hiredate,i.hiredate),
sal = nvl(:sal,i.sal),
comm = nvl(:comm,i.comm),
deptno = nvl(:deptno,i.deptno)
where empno = :id;
end loop;
--
if SQL%FOUND then
:status := 200; -- success
commit;
else
:status := 400;
:errmsg := 'Employyee not found';
end if;
else
:status := 400;
:errmsg := 'Employyee Number muust be specified';
end if;
exception
when others then
:status := 400;
:errmsg := sqlerrm;
end;
--------------------------------------------
I executed the GET method in postman, and it's ok
but when i executed the POST method with the body /
{
"ename": "TAREK",
"job": "ANALYST",
"mgr": null,
"hiredate": "1981-11-17T00:00:00Z",
"sal": 5000,
"comm": null,
"deptno": 10
}
THE ROW IS CREATED but all the columns are nulls juste the empno that create automaticly,
i executed a PUT method the result is ok but when i select the row was update i find the old value in the column that updated,
can you please advace me how resolve this issue?
i'm beginner in APEX and the REST method
Thanks