Home > database >  Is it possible to pass bind variable as parameter?
Is it possible to pass bind variable as parameter?

Time:07-19

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;

CodePudding user response:

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;
/
  • Related