0

I am trying to call a stored procedure with in a stored procedure using SQL language.

call Parent_Proc(varchar, varchar, array)

var 1 = PROCESS_TBL
Var 2 = AUDIT_TBL
Var 3 = [PROCESS_NM1, PROCESS_NM2, PROCESS_NM3]

while loop:
call child_proc(var 1,var 2,var 3[1] )

return process_nm +'response from child proc'

I am trying to apply while loop but getting error, also need to return success/failure status for each process_nm in the end.

My code :

CREATE OR REPLACE PROCEDURE Parent_Proc(process_tbl varchar ,audit_tbl varchar,process_nm array)       
returns varchar
as $$ 
declare
COUNTER int default 1;
begin
  while (COUNTER <= process_name.length) do
    call Child_Proc(process_tbl ,audit_tbl,process_nm[COUNTER-1]);
    COUNTER := COUNTER + 1;
    return 
   end while;

end;

$$;

Getting error invalid Identifier process_nm

1
  • 1
    the fact you want to do this this way suggests you have an XY problem. Commented Feb 27, 2023 at 12:19

1 Answer 1

0

You need to use ARRAY_SIZE instead of process_name.length:

https://docs.snowflake.com/en/sql-reference/functions/array_size

CREATE OR REPLACE PROCEDURE Parent_Proc(process_tbl varchar ,audit_tbl varchar,process_nm array)       
returns varchar
as  
declare
  COUNTER int default 1;
  tmp varchar;
begin
  while (COUNTER <= ARRAY_SIZE(process_nm) ) do
    tmp := process_nm[COUNTER-1] ;
    call Child_Proc( :process_tbl ,:audit_tbl, :tmp );
    COUNTER := COUNTER + 1;
    -- return 'XYZ'
   end while;
end;
4
  • Now I am getting PROCESS_TBL invalid identifier Commented Feb 27, 2023 at 14:29
  • Updated my answer to use CALL! @user13975334 Commented Feb 27, 2023 at 14:38
  • I was curious how to return status of each call . For example for: Process_nm1 + Succeeded \n Process_nm2 +Failed Commented Feb 28, 2023 at 1:39
  • As I see you already asked a new question about it - I will check it. If my answer was correct (as I see you use the same code on your next question), can you mark it as "correct answer"? Commented Feb 28, 2023 at 8:06

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.