Home > database >  SQL server custom function call a stored procedure
SQL server custom function call a stored procedure

Time:10-01

Now meet the database type,
The original database is oracle needs to move to the used
Have a custom function of ora and call a stored procedure in the custom function,

, used the custom function and there is no way to call a stored procedure?

CodePudding user response:

MSSQL, however, does not support the exec function execution

CodePudding user response:

reference 1/f, illiterate old gu response:
however, MSSQL does not support the function exec


There is a solution?

CodePudding user response:

Do the following test, and does not support function call a stored procedure within
Only functions provides the and some extended stored procedures can be executed from within a function.



Create table test
(col1 int)

Insert into test values (1)

Create procedure insertTest
As
The begin
Insert into test
Select count (*) + 1 from the test
End

The CREATE FUNCTION getTestCount
()
RETURNS the int
AS
The BEGIN

The exec insertTest
Declare @ testCount int
Select @ testCount=(select count (*) from test)

RETURN the @ testCount

END
GO

The select dbo. GetTestCount ()

CodePudding user response:

The regulation of no solution, the somebody else is in this way,
You can do SQLCLR function, whether can try,

CodePudding user response:

This can only modify the code, put the business logic in the stored procedure into the function,

CodePudding user response:

Used to not have this kind of writing!

CodePudding user response:

Try to rewrite, write a stored procedure function
Function limits, of course, if can't change, try to make calls to functions into a stored procedure call

CodePudding user response:

The function in the SQL Server can not call a stored procedure,
And, the function cannot perform addition, deletion and does not support exception information intercepted,

Corresponding methods are as follows:
1. If only exception information in function call a stored procedure, can remove the exception handling, storage process,
2. If the function to be deleted, the increase in the correction function for the stored procedure,
3. The function calls, if simply not in the text, add and delete SQL execution, correction function for the stored procedure,

CodePudding user response:

reference 4 floor gypsy song response:
no solution, the rules of the family is in this way,
You can do SQLCLR function, whether can try,


Can you give a "chestnut"?
  • Related