How to use One procedure output variable data into another procedure - oracle

I have one requirement in which I have to design two procedure.First procedure will generate one output variable value and then second procedure will use to do its task. I am giving same kind of scenario in below code
create procedure existingProc(
begin
insert statementprogramming statement
);
create procedure MyProc(
begin
call existingProc();
-- Exsisting procedure return some value
-- and this value is used in MyProc
commit;
);
In the above code existingProc is already there in the system and I can not change it. IN the procedure transaction is begin but not committed. This procedure generate one value as Output param and MyProc will used this value.
I want that after executing the existingProc, MyProc procedure should get the value, but it is not happening and it is giving null.
what should i do here, Please help me. I can not share the code that why giving scenario.

Does this help clarify how to use the output parameters from one procedure in another procedure?
create procedure ExistingProc(output1 out number) is
begin
insert into someTable values ('some values')
RETURNING someCol INTO output1;
end;
create procedure MyProc(args ....) is
Result1 number; --output from existingProc
begin
ExistingProc(result1);
-- Use Result1 as needed
Update stuff ...
where id = Resutl1;
commit;
end;

Related

Not able to call procedure in Oracle APEX

I am trying to call procedure in oracle apex but I am facing problem in displaying the output of procedure while passing the parameter as emp_id to that procedure from oracle apex. Can anyone help me?
procedure that I have written in SQL developer tool.
create or replace PROCEDURE TEST_PROC(EMP_ID1 IN Number)
As
RESULT TIMESHEET_EMPLOYEES%ROWTYPE;
BEGIN
SELECT * INTO RESULT.EMP_ID,RESULT.NAME,RESULT.LOCATION,RESULT.CITY,RESULT.COUNTRY,RESULT.EMPLOYMENT_TYPE,RESULT.EMAIL_ID,RESULT.PHONE_NUMBER,RESULT.CREATED_BY,RESULT.CREATED_ON,RESULT.UPDATED_ON,
RESULT.UPDATED_BY,RESULT.DATE_OF_JOINING,RESULT.ROLE_ID,RESULT.SUPERVISOR_ID FROM TIMESHEET_EMPLOYEES
WHERE EMP_ID=EMP_ID1;
DBMS_OUTPUT.PUT_LINE('EMP_ID:'||RESULT.EMP_ID||' '||'NAME:'||RESULT.NAME||' '||'LOCATION:'||RESULT.LOCATION||' '||'CITY:'||RESULT.CITY ||' '||'COUNTRY:'||RESULT.COUNTRY||' '||'EMPLOYMENT_TYPE:'||
RESULT.EMPLOYMENT_TYPE||' '||'EMAIL_ID:'||RESULT.EMAIL_ID||' '||'PHONE_NUMBER:'||RESULT.PHONE_NUMBER||' '||'CREATED_BY:'||RESULT.CREATED_BY||' '||'CREATED_ON:'||RESULT.CREATED_ON||' '||'UPDATED_ON:'||
RESULT.UPDATED_ON||' '||'UPDATED_BY:'||RESULT.UPDATED_BY||' '||'DATE_OF_JOINING:'||RESULT.DATE_OF_JOINING||' '||'ROLE_ID:'||RESULT.ROLE_ID||' '||'SUPERVISOR_ID:'||RESULT.SUPERVISOR_ID);
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('SQLCODE'||' '||SQLCODE);
DBMS_OUTPUT.PUT_LINE('SQLERRM'||' '||SQLERRM);
END;
herein oracle apex in PLSQL code I am trying to call that procedure but I am not able to see any output.
BEGIN
TEST_PROC(:P1_EMPID);
END;
Can someone help me as I am new to APEX???
Apex can't display result of DBMS_OUTPUT.PUT_LINE.
Two simple options you might use:
add another, OUT parameter(s) to your current procedure, or
convert this procedure to a function which returns the result as a concatenated string
Both of them should return the result into an item on the page.
For example, if it were a procedure:
create or replace PROCEDURE TEST_PROC(EMP_ID1 IN Number,
par_result out varchar2
)
is
-- ... your current code goes here; I presume it does what you wanted
-- at the end, return the result as
par_result := 'EMP_ID:'||RESULT.EMP_ID||' '||'NAME:'||RESULT.NAME || ...
end;
Call it in a process as
TEST_PROC(:P1_EMPID, :P1_RESULT);
As of code you wrote: if you declared result as %rowtype, it is simpler to insert directly into it, not into every separate piece of it. For example:
select *
into result --> this
from timesheet_employees
where emp_id = emp_id1;

call plsql procedure with parameters

I tried to call this procedure but have some issues
CREATE OR REPLACE Procedure InsertNewReservation
( flight_number IN varchar2,passenger_id IN number,flight_price in number )
IS
s2 number;
BEGIN
insert into Reservations (flightNumber,passengerId) values (flight_number,passenger_id)
returning ID into s2;
insert into Payments (value,reservationId) values (flight_price,s2);
END;
/
How do I call the procedure ?
I tried
BEGIN
InsertNewReservation('FL100',1,120);
END;
/
But it didn't work :/
Thanks!
Because there's no ID column, but passengerId within the Reservations table :
CREATE OR REPLACE Procedure InsertNewReservation
(
flight_number Reservations.flightNumber%type,
passenger_id Reservations.passengerId%type,
flight_price Payments.value%type
)
IS
s2 Payments.reservationId%type;
BEGIN
insert into Reservations (flightNumber,passengerId)
values(flight_number,passenger_id) returning passengerId into s2;
insert into Payments (value,reservationId) Values (flight_price,s2);
END;
/
btw, replace the variables so as to conform their respective types within the table, and using IN operator is redundant for parameter type of the procedure as being the default.
Demo
Remove the exec keyword, which is not used in a PL/SQL block:
begin
InsertNewReservation('FL100',1,120);
end;
exec is used in tools like SQL Plus to run a procedure outside a PL/SQL block:
SQL> exec InsertNewReservation('FL100',1,120);

PL SQL Procedure from Trigger

I created procedure GETDEL that select name from students , but when i try to call this procedure in trigger it says i gave wrong types of argument to call
I have been trying to pass (records) or (records OUT SYS_REFCURSOR) as a argument but it dont works
CREATE OR REPLACE PROCEDURE GETDEL(records OUT SYS_REFCURSOR) AS
BEGIN
OPEN records FOR
SELECT name FROM students;
END GETDEL;
CREATE OR REPLACE TRIGGER After_delete_student
AFTER DELETE ON TABLE2
FOR EACH ROW
DECLARE
rec sys_refcursor;
BEGIN
GETDELCZL();
END;
Your procedure contains a single parameter and, even though it's an out parameter, the calling procedure is responsible the defining it.
create or replace
trigger after_delete_student
after delete
on table2
for each row
declare
result_rec sys_refcursor;
begin
getdel(result_rec);
end;

How to call another Procedure in CASE WHEN in Oracle Procedure

I have created many Procedures to extract the data from remote database and stored it in my local database tables. The procedures run successfully when i run it individually. But now i want to create dynamic procedure which will call based on conditions. I have created small procedure for the same but getting an error when i run this procedure as :
ORA-06512:
01403. 00000 - "no data found"
I am calling the procedure as EXT_EXTRACTION(1000161);
I think the problem is i am not calling the Procedure in CASE WHEN properly and don't know how to call it correctly.
Here is my procedure;
PROCEDURE "EXT_EXTRACTION"(
IN_KPI_DEF_ID IN NUMBER DEFAULT 0
) AS
ENTITY_CLASS_NAME Number := 0;
IN_EVENT_ID NUMBER;
BEGIN
Select EVENT_ID
INTO IN_EVENT_ID
from RATOR_MONITORING_CONFIGURATION.KPI_DEFINITION
WHERE KPI_DEF_ID = IN_KPI_DEF_ID;
CASE
WHEN IN_EVENT_ID = 10049
THEN EXT_10049_ACTIVATE_OPTION;
END CASE;
COMMIT;
END EXT_EXTRACTION;
Try to surround select in your procedure with exception when no_data_found and look at result. May be this proc work from another user,which have no priveleges to select, or selected object is a view? May be you should create procedure like authid current_user?

Calling a stored PROCEDURE in Toad

I have a defined a new stored procedure but get a error while calling it,
CREATE OR REPLACE PROCEDURE SCOTT.getempsal(
p_emp_id IN NUMBER,
p_emp_month IN CHAR,
p_emp_sal OUT INTEGER)
AS
BEGIN
SELECT EMP_SAL
INTO p_emp_sal
FROM EMPLOYEE_SAL
WHERE EMP_ID = p_emp_id
AND EMP_MONTH = p_emp_month;
END getempsal;
And trying to call it:
getempsal(1,'JAN',OUT) --Invalid sql statement.
Your procedure contains an out parameter, so you need to call it in block like:
declare
a number;
begin
getempsal(1,'JAN',a);
dbms_output.put_line(a);
end;
A simple procedure (let's say with a number parameter) can be called with
exec proc(1);
or
begin
proc(1);
end;
Just write EXECUTE procedure_name('provide_the_valueof_IN parameter','value of in parameter', :k) ;
Run this statement a popup will come set the parameters as in out and the datatype too. U will see the output in another popup window.

Resources