函数能被SQL语句调用,存储过程不能。为了能够被SQL语句调用,函数必须遵循purity规则,这些规则能控制函数的副作用:
该规则也适用于被该函数调用的函数或过程。The same rules that apply to the function itself also apply to any functions or procedures that it calls.
副作用越少,查询就越能对此函数进行优化。The fewer side-effects a function has, the better it can be optimized within a query, particular when the PARALLEL_ENABLE or DETERMINISTIC hints are used.
如果被SQL调用的函数违反了规则,就会得到runtime error.
为了(让编译器??)检查是否违背了规则,我们可以使用 pragma RESTRICT_REFERENCES。该编译指示断言函数不会读/写数据表/包变量。
但只能用于package spec or object type spec,不能用于独立函数和独立过程。
RNDS | WNDS| RNPS| WNPS | TRUST
来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/9844649/viewspace-580048/ ,如需转载,请注明出处,否则将追究法律责任。