E
Eric
I'm new in the oracle world and I simply try to call a stored
procedure with output parameter. I have seen that most people are
using stored procedure in package (especially when using cursors). My
first question : is it possible to get query result without using
packages and cursors.For exemple simply returning simple data type.
I have tried the following:
CREATE OR REPLACE PROCEDURE SP_TEST(Code IN
f_captive.cap_code%type,Nom OUT f_captive.cap_nom%type)
IS
BEGIN
SELECT cap_nom
INTO Nom
FROM f_captive
WHERE cap_code like Code;
END;
The C# code calling the stored procedure is the following:
OleDbConnection con=new
OleDbConnection(@"Provider=MSDAORA.1;Password=mypsw;User ID=me;Data
Source=mydsn");
con.Open();
string sp_request= "SP_CAPTIVES";
OleDbCommand cmd=new OleDbCommand(sp_request,con);
cmd.CommandType = CommandType.StoredProcedure;
OleDbParameter Param= cmd.Parameters.Add("Code",OleDbType.VarChar,2);
Param.Direction = ParameterDirection.Input ;
Param.Value = m_sCapCode;
OleDbParameter out_Name=cmd.Parameters.Add("Nom",OleDbType.VarChar,35);
out_Name.Direction = ParameterDirection.Output ;
OleDbDataReader dr=cmd.ExecuteReader();
dr.Read();
string sFieldCount = dr.FieldCount.ToString();
by using this syntax for sp_request string to call the stored
procedure the the resulset is empty and no row is returned but it
should because tested in SQL Worksheet it returns one row as expected.
using the ODBC Escape syntax "{call SP_CAPTIVES(?,?)}" I get a error
telling that the ODBC Escape syntax is wrong.
Then i try with named variables "{call SP_CAPTIVES(Code,Nom)}", i was
the same error message.
Always in the goal to execute the same query I tried to use the
following function:
CREATE OR REPLACE FUNCTION GET_CAPTIVES(Code IN
f_captive.cap_code%type)
RETURN f_captive.cap_nom%type
IS
Nom f_captive.cap_nom%type;
BEGIN
SELECT cap_nom
INTO Nom
FROM f_captive
WHERE cap_code like Code;
RETURN Nom;
END;
And i modified my C# code in consequence:
OleDbConnection con=new
OleDbConnection(@"Provider=MSDAORA.1;Password=mypsw;User ID=me;Data
Source=mydsn");
con.Open();
string sp_request= "GET_CAPTIVES";
OleDbCommand cmd=new OleDbCommand(sp_request,con);
cmd.CommandType = CommandType.StoredProcedure;
OleDbParameter Param= cmd.Parameters.Add("Code",OleDbType.VarChar,2);
Param.Direction = ParameterDirection.Input ;
Param.Value = m_sCapCode;
OleDbParameter out_Name=cmd.Parameters.Add("Nom",OleDbType.VarChar,35);
out_Name.Direction = ParameterDirection.ReturnValue; //CHANGE FOR
FUNCTION
OleDbDataReader dr=cmd.ExecuteReader();
dr.Read();
Then I get the following error:
ORA-06550: line 1 , column 7
PLS-00306: bad number or argument type
PL/SQL : statement ignored -2147217900
the real argument type in the DB is Varchar2(2) for input parameter
Code
and Varchar2(35) for output parameter Nom.
Could someone tell me where I did wrong or give me some help to go on
the right way to call a oracle store procedure
thanks in advance
Eric
procedure with output parameter. I have seen that most people are
using stored procedure in package (especially when using cursors). My
first question : is it possible to get query result without using
packages and cursors.For exemple simply returning simple data type.
I have tried the following:
CREATE OR REPLACE PROCEDURE SP_TEST(Code IN
f_captive.cap_code%type,Nom OUT f_captive.cap_nom%type)
IS
BEGIN
SELECT cap_nom
INTO Nom
FROM f_captive
WHERE cap_code like Code;
END;
The C# code calling the stored procedure is the following:
OleDbConnection con=new
OleDbConnection(@"Provider=MSDAORA.1;Password=mypsw;User ID=me;Data
Source=mydsn");
con.Open();
string sp_request= "SP_CAPTIVES";
OleDbCommand cmd=new OleDbCommand(sp_request,con);
cmd.CommandType = CommandType.StoredProcedure;
OleDbParameter Param= cmd.Parameters.Add("Code",OleDbType.VarChar,2);
Param.Direction = ParameterDirection.Input ;
Param.Value = m_sCapCode;
OleDbParameter out_Name=cmd.Parameters.Add("Nom",OleDbType.VarChar,35);
out_Name.Direction = ParameterDirection.Output ;
OleDbDataReader dr=cmd.ExecuteReader();
dr.Read();
string sFieldCount = dr.FieldCount.ToString();
by using this syntax for sp_request string to call the stored
procedure the the resulset is empty and no row is returned but it
should because tested in SQL Worksheet it returns one row as expected.
using the ODBC Escape syntax "{call SP_CAPTIVES(?,?)}" I get a error
telling that the ODBC Escape syntax is wrong.
Then i try with named variables "{call SP_CAPTIVES(Code,Nom)}", i was
the same error message.
Always in the goal to execute the same query I tried to use the
following function:
CREATE OR REPLACE FUNCTION GET_CAPTIVES(Code IN
f_captive.cap_code%type)
RETURN f_captive.cap_nom%type
IS
Nom f_captive.cap_nom%type;
BEGIN
SELECT cap_nom
INTO Nom
FROM f_captive
WHERE cap_code like Code;
RETURN Nom;
END;
And i modified my C# code in consequence:
OleDbConnection con=new
OleDbConnection(@"Provider=MSDAORA.1;Password=mypsw;User ID=me;Data
Source=mydsn");
con.Open();
string sp_request= "GET_CAPTIVES";
OleDbCommand cmd=new OleDbCommand(sp_request,con);
cmd.CommandType = CommandType.StoredProcedure;
OleDbParameter Param= cmd.Parameters.Add("Code",OleDbType.VarChar,2);
Param.Direction = ParameterDirection.Input ;
Param.Value = m_sCapCode;
OleDbParameter out_Name=cmd.Parameters.Add("Nom",OleDbType.VarChar,35);
out_Name.Direction = ParameterDirection.ReturnValue; //CHANGE FOR
FUNCTION
OleDbDataReader dr=cmd.ExecuteReader();
dr.Read();
Then I get the following error:
ORA-06550: line 1 , column 7
PLS-00306: bad number or argument type
PL/SQL : statement ignored -2147217900
the real argument type in the DB is Varchar2(2) for input parameter
Code
and Varchar2(35) for output parameter Nom.
Could someone tell me where I did wrong or give me some help to go on
the right way to call a oracle store procedure
thanks in advance
Eric