Is it possible to pass bind variable as parameter?

279 Views Asked by At

Is it possible to pass a bind variable to a procedure? Here a simplified snippet, to show what I'm trying to do:

CREATE OR REPLACE PROCEDURE TEST_CSV ( :d1 IN DATE DEFAULT null, :n1 IN NUMBER DEFAULT null)
IS 
BEGIN    
    SELECT DISTINCT * from table WHERE MY_NUM = :n1;    
END;
1

There are 1 best solutions below

0
Boneist On BEST ANSWER

I think you've misunderstood how procedures work.

You define a procedure (or function) with parameters, the values of which get passed in from the calling code.

Therefore, you would define the procedure with named parameters, e.g.

CREATE OR REPLACE PROCEDURE TEST_CSV (d1 IN DATE DEFAULT null,
                                      n1 IN NUMBER DEFAULT null)
IS 
BEGIN    
    SELECT DISTINCT * from table WHERE MY_NUM = n1;    
END;
/

and you would call the procedure passing in the values - which could be bind variables, e.g.:

BEGIN
  test_csv (d1 => :d1,
            n1 => :n1);
END;
/