我在 Oracle 包中定义了一个函数:
CREATE OR REPLACE PACKAGE BODY TESTUSER.TESTPKG as
FUNCTION testfunc(n IN NUMBER) RETURN NUMBER as
begin
return n + 1;
end testfunc;
end testpkg;
/
如何使用 Odbc 从 C# 调用它?我尝试了以下方法:
using System;
using System.Data;
using System.Data.Odbc;
class Program {
static void Main(string[] args) {
using (OdbcConnection connection = new OdbcConnection("DSN=testdb;UID=testuser;PWD=testpwd")) {
connection.Open();
OdbcCommand command = new OdbcCommand("TESTUSER.TESTPKG.testfunc", connection);
command.CommandType = System.Data.CommandType.StoredProcedure;
command.Parameters.Add("ret", OdbcType.Int).Direction = ParameterDirection.ReturnValue;
command.Parameters.Add("n", OdbcType.Int).Direction = ParameterDirection.Input;
command.Parameters["n"].Value = 42;
command.ExecuteNonQuery();
Console.WriteLine(command.Parameters["ret"].Value);
}
}
}
但是我得到一个异常提示“无效的 SQL 语句”。
我做错了什么?
最佳答案
关于c# - 从 C# 使用 Odbc 调用 Oracle 包函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2949641/