我正试图从access中的vba调用一个类似这样的存储函数:
SELECT my_function();
如果它是一个存储过程,它会是这样的:
CALL my_procedure();
对于存储过程,我可以使用:
Dim cmd As Object
Set cmd = CreateObject("ADODB.Command")
With cmd
Set .ActiveConnection = oConn 'ADODB connection created elsewhere
.CommandType = adCmdStoredProc
.CommandText = "my_procedure"
End With
cmd.execute
具体来说,我想知道函数是否有等效的"adCmdStoredProc"?
">具体来说,我想知道函数是否有等效的‘adCmdStoredProc’?">
但是您使用的SQL是一个SELECT,它引用了一个函数:
SELECT my_function();
CommandTypeEnum中有7个选项adCmdUnspecified应该有效;可能adCmdUnknown。我会使用adCmdText,但它并不是函数的"等价物"。
CommandTypeEnum Constants
Constant Value Description
adCmdFile 256 Evaluate as a previously persisted file
adCmdStoredProc 4 Evaluate as a stored procedure
adCmdTable 2 Have the provider generate a SQL query and return all rows from the specified table
adCmdTableDirect 512 Return all rows from the specified table
adCmdText 1 Evaluate as a textual definition
adCmdUnknown 8 The type of the CommandText parameter is unknown
adCmdUnspecified -1 Default, does not specify how to evaluate
您是否尝试将其作为SELECT
语句运行?
SELECT *
FROM my_function()