PL/SQL passing functions as parameters

后端 未结 1 1658
[愿得一人]
[愿得一人] 2021-01-19 10:57

I\'ve programmed in PL/SQL during half an year and I had the impression it\'s a quite plain programming language (IMHO). Although I\'ve stumbled upon interesting articles, l

相关标签:
1条回答
  • 2021-01-19 11:08

    You can't pass a function as a parameter directly. The best you could do is use dynamic PL/SQL to execute a function passed in as a string. I do not recommend this. I can see the use of dynamic PL/SQL in a few cases, but this opens you up to all sorts of problems.

    DECLARE 
       PROCEDURE inner_function
       IS
       BEGIN
           dbms_output.put_line('Output');
       END;
    
       PROCEDURE tell_me(parm_function varchar2) 
       IS
       BEGIN
           EXECUTE IMMEDIATE 'BEGIN '||parm_function||'(); END;';
       END;
    
    BEGIN
       tell_me('inner_function');
    END;
    

    DBMS_OUTPUT should just have "Output" in the buffer.

    This may not work since inner_function may be out of scope. In that case, define the procedure in the schema itself.

    0 讨论(0)
提交回复
热议问题