Reputation: 87
I am trying to create a stored procedure which takes a dynamic number of parameters and creates a SQL table based on the parameters given to it.
I know initially that there will be 7 columns, but there could be more.
I am working in Snowflake.
Upvotes: 1
Views: 555
Reputation: 727
The parameters need to be defined in the Stored Proc.
To pass a variable numbers of parms, you can pass the parameters as a delimited list in a string, so you are passing a single string parameter, then the stored procedure can split the string and loop through each element of the array.
MYVAR = 'A~B~C';
CREATE PROCEDURE PROCABC(MYVAR VARCHAR)
RETURNS VARCHAR
LANGUAGE JAVASCRIPT
AS
$$
var ARRAY_STR = MYVAR.split("~");
//process ARRAY_STR in a loop
Upvotes: 2