How to pass bind variable as IN OUT parameter in PLSQL procedure

1.5k Views Asked by At

I want to use 1st parameter of my procedure EMP_ID as IN OUT parameter. Originally it's IN parameter and this procedure is working fine, but as the last line concern

htp.p('Inserted for Employee-id '||EMP_ID);

I want to use this line in anonymous block and most importantly it should be a bind variable because I am creating the REST API in which user will only enter values and it will be taken as bind variable in oracle Apex and the below procedure is working fine with respect of IN parameter.

create or replace procedure att_time_ins (EMP_ID in  varchar2, ORG_ID in number,V_TIME_STATUS in number) is
  BEGIN
INSERT INTO TIME_ATTENDANCE_POOL
(EMPLOYEE_ID, ATTENDANCE_DATE,TIME_HOURS,TIME_MINUTES,TIME_STATUS,LOCATION_ID,ORG_ID,PREPARED_ON )  
VALUES  
(EMP_ID, to_date(sysdate,'DD/MM/YYYY'),to_char(sysdate,'HH24') ,to_char(sysdate,'MI'),V_TIME_STATUS,null,ORG_ID,
to_date(sysdate,'DD/MM/YYYY') );   
COMMIT;

time_management.create_attendance_sheet(v_org_id => ORG_ID,
                                          v_employee_id => EMP_ID,
                                          target_date =>  to_date(sysdate,'DD/MM/YYYY'));
 htp.p('Inserted for Employee-id '||EMP_ID);



end att_time_ins;

I am calling my procedure in this way

begin
 
  att_time_ins(:employee_id,:org_id,:time_status);
 
end;

Please help me to modify this stuff according to IN OUT Parameter i.e Employee_id should be IN OUT parameter. There is no proper documentation regarding passing bind variables as in out prameter in PLSQL Block.

1

There are 1 best solutions below

0
On

Let us say you have a procedure named PR_PROC, you can use VARIABLE statement for passing IN OUT or OUT kind of variables.

CREATE OR REPLACE PROCEDURE PR_PROC (EMP_NAME   IN     VARCHAR2,
                                     EMP_ID     IN OUT VARCHAR2)
IS
BEGIN
   DBMS_OUTPUT.PUT_LINE (EMP_NAME||EMP_ID);

END;
   
VARIABLE KURSOR VARCHAR2
BEGIN
 :KURSOR:='4';
 PR_PROC('SENIOR',:KURSOR);
END;

Note: If you are using TOAD Editor you can press F5 to make it work.

Oracle VARIABLE