One of the main differences between UDF and SP is that UDF can only have select statements inside it and not insert/update/delete statements. Can someone please explain the reason behind this? The below function:
create function test(..)
...
BEGIN
insert into EMPLOYEE('22',12000,'john');
return 0;
END
is not valid. But why is this so?
Best Answer
This is not about function (UDF) vs procedure. It is the context where you use them.
You can have DML operations in a function:
But if you use your function as and UDF in a query:
You can still work around this with an autonomous transaction:
But should you do this? I do not think so.