Difference between a inline function and a view

前端 未结 9 1141
悲哀的现实
悲哀的现实 2020-12-19 11:17

I am a newbie in using functions and it appears to me that an inline function is very similar to a view. Am I correct?

Also, can I have UPDATE statements within a fu

9条回答
  •  半阙折子戏
    2020-12-19 12:04

    One big difference is that a function can take parameters whereas a VIEW cannot.

    I tend to favour VIEWs, being a Standard and therefore portable implementation. I use functions when the equivalent VIEW would be meaningless without a WHERE clause.

    For example, I have a function that queries a relatively large valid-time state table ('history' table). If this was a VIEW and you tried to query it without a WHERE clause you'd get a whole lot of fairly data (eventually!) Using a function establishes a contract that if you want the data then you must supply a customer ID, a start date and an end date and the function is how I establish this contact. Why not a stored proc? Well, I expect a user to want to JOIN the resultset to further data (tables, VIEWs, functions, etc) and a function is IMO the best way of doing this rather then, say, requiring the user to write the resultset to a temporary table.

提交回复
热议问题