Rufen Sie die Oracle -Paketfunktion mit ODBC von C# auf

Post a reply

Smilies
:) :( :oops: :chelo: :roll: :wink: :muza: :sorry: :angel: :read: *x) :clever:
View more smilies

BBCode is ON
[img] is ON
[flash] is OFF
[url] is ON
Smilies are ON

Topic review
   

Expand view Topic review: Rufen Sie die Oracle -Paketfunktion mit ODBC von C# auf

by Anonymous » 20 May 2025, 16:47

Ich habe eine Funktion in einem Oracle -Paket definiert: < /p>

CREATE OR REPLACE PACKAGE BODY TESTUSER.TESTPKG as
FUNCTION testfunc(n IN NUMBER) RETURN NUMBER as
begin
return n + 1;
end testfunc;
end testpkg;
/
< /code>

Wie kann ich es mit ODBC von C# aufrufen? Ich habe Folgendes ausprobiert: < /p>

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);
}
}
}
< /code>

, aber ich erhalte eine Ausnahme mit der Aufschrift "Ungültige SQL -Anweisung".

Was mache ich falsch? < /p>

Top