Calling Oracle Functions

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

Call someone tell me if it is possible to call Oracle Functions with System.Data.OracleClient classes? I have a simple function that returns a varchar and it keeps telling me it isn't a valid proc, well of course it's not a proc, its a function.
I don't want to have to use OleDB... if I don't have to.

Thanks
 
Steve said:
Call someone tell me if it is possible to call Oracle Functions with
System.Data.OracleClient classes? I have a simple function that returns a
varchar and it keeps telling me it isn't a valid proc, well of course it's
not a proc, its a function.
I don't want to have to use OleDB... if I don't have to.

Thanks

It's just a matter of getting your parameter bindings right.

But instead of giving an example, here's how to investigate, work around and
solve any such problem:

Write a PL/SQL block do make the call.

If you want to call a function called my_function
create or replace function my_function
return varchar2
....

then use a commandText like
"begin :p_return := my_function(:p_input); end;"

Then bind an output parameter to :p_return and an input parameter to
:p_input.

You can run exactly the same commandText in SQLPlus or Toad or whatever to
test. And you can also hard-code the parameters for testing. For instance
you can run

"declare l_rv varchar2(255); begin l_rv := my_function(123); end;"
That's

declare
l_rv varchar2(255);
begin
l_rv := my_function(123);
end;

for readablility, and in C# you can write

string sql = @"
declare
l_rv varchar2(255);
begin
l_rv := my_function(123);
end;
";

and have both readablility and cut-and-pasteablility.

David
 
Back
Top