开发者

Calling MySql stored function rather than a stored procedure with ADO Command object

开发者 https://www.devze.com 2023-03-17 04:49 出处:网络
I\'m trying to call a stored function like this from vba in access: SELECT my_function(); If it were a stored procedure it would be like this:

I'm trying to call a stored function like this from vba in access:

SELECT my_function();

If it were a stored procedure it would be like this:

CALL my_procedure();

For the stored procedure I can use:

Dim cmd As Object
Set cmd = CreateObject("ADODB.Command")

With cmd
    Set .ActiveConnection = oConn 'ADODB connection created elsewhere
    .CommandType = adCmdStoredProc
    .CommandText = "my_procedu开发者_运维知识库re"
End With

cmd.execute

Specifically I'd like to know if there is an equivalent of 'adCmdStoredProc' for functions?


"Specifically I'd like to know if there is an equivalent of 'adCmdStoredProc' for functions?"

But the SQL you're using is a SELECT which references a function:

SELECT my_function();

You have 7 choices from the CommandTypeEnum. adCmdUnspecified should work; probably adCmdUnknown too. I would use adCmdText, but it's not really "the equivalent of" adCmdStoredProc for a function.

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


Have you tried running it as a SELECT statement?

SELECT *
FROM my_function()
0

精彩评论

暂无评论...
验证码 换一张
取 消