I would like to update data in a table (for sqlserver and oralce version).
I created a stored procedure as below, but i would like to convert it to SQL function, is it possible to update data within SQL function please?
CREATE PROCEDURE updatetable (@A1 INTEGER, @A2 VARCHAR(4000) )
AS
BEGIN
BEGIN
UPDATE table SET column1= column1 @A1 WHERE column2= @A2 ;
END
END
CodePudding user response:
For SQL Server.
Simply put:
No.
A function can't change the system (really gross and dangerous hacks aside). From the documentation (emphasis mine):
Specifies that a series of Transact-SQL statements, which together do not produce a side effect such as modifying a table
If you can explain what you're trying to accomplish with a function that you can't accomplish with a stored procedure, you might be asking a question that has more than a yes/no answer, and you might get useful alternatives.