Functions vs procedures in Oracle

后端 未结 7 1827
鱼传尺愫
鱼传尺愫 2020-12-04 15:18

can anybody explain what is the main difference between functions and procedures in Oracle? Why must I use procedures if I can do everything with functions?

  1. I
7条回答
  •  渐次进展
    2020-12-04 15:50

    State-changing vs non-state-changing

    On top of Romo Daneghyan's answer, I've always viewed the difference as their behaviour on the program state. That is, conceptually,

    • Procedures can change some state, either of the parameters or of the environment (eg, data in tables etc).
    • Functions do not change state, and you would expect that calling a particular function would not modify any data/state. (Ie, the concept underlying functional programming)

    Ie, if you called a function named generateId(...), you'd expect it to only do some computation and return a value. But calling a procedure generateId ..., you might expect it to change values in some tables.

    Of course, it seems like in Oracle as well as many languages, this does not apply and is not enforced, so perhaps it's just me.

提交回复
热议问题