Click here to Skip to main content
15,901,001 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
hi guys.
im new on PL/SQL. i need help or advice on how to solve a problem.
i have functions 1 and 2 with a input who simply returns count(*),
now the problem is when i wane write a third function or procedure and call this 2.
i want the third function or procedure to select the table and call the functions to see how many rows with the specific id has so i can later do some validation.
is this possible DOTO:?

SQL
/* function 1 */
CREATE OR REPLACE FUNCTION total_SV_rows(val number)
RETURN number IS
   total number := 0;
BEGIN

   SELECT DISTINCT count(*) into total
   FROM TMP_SV TSV
   WHERE TSV.CODE_LABEL = '47' || val;
   RETURN total;
   
END;
/

/* function 2 */
CREATE OR REPLACE FUNCTION total_IRIS_rows(val number)
RETURN number IS
   total number := 0;
BEGIN

   SELECT DISTINCT count(*) into total
   FROM TMP_SUBPRODUCT_IRIS TSI
   WHERE TSI.MSISDN = val;
   RETURN total;
END;
/



/* wane call function 1 and 2 here  */
create or replace PROCEDURE get_TMP_SUBPRODUCT_IRIS AS

BEGIN
   for i IN   (
        select TSI.MSISDN msisdn, TSI.PRODUCT_NAME p_name, TSI.EXT_ID_REF ref_id,                TSI.ACTIVATION_DATE act_date
        from TMP_SUBPRODUCT_IRIS TSI
        where MSISDN = 97198252
   )
   LOOP
        DBMS_OUTPUT.PUT_LINE ('write output');
   end loop;

END get_TMP_SUBPRODUCT_IRIS;
Posted
Updated 16-Feb-15 22:04pm
v2

1 solution

Sql Function has some limitation,instead of using Function you can use Store Procedure.
Sp VS Fun[^]

This is possible using Store procedure.

SQL
Create PROCEDURE Sp1(
@par1 varcahr(50)

)
begin

---do your work
End

Create PROCEDURE Sp2(
@par1 varcahr(50)

)
begin

---do your work
End


Create PROCEDURE Sp3(
@par1 varcahr(50)

)
begin

declare @anyparams as varchar(50)
set @anyparams ='value'-- set parameter value before calling the called  SP
Exec Sp2 @anyparams --calling Store procedure sp2 from this one
---do your work
End

ref.
http://stackoverflow.com/questions/15802511/execute-a-stored-procedure-in-another-stored-procedure-in-sql-server[^]
http://blog.sqlauthority.com/2013/04/07/sql-server-pass-one-stored-procedures-result-as-another-stored-procedures-parameter/[^]
http://www.mssqltips.com/sqlservertutorial/163/returning-stored-procedure-parameter-values-to-a-calling-stored-procedure/[^]
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900