调用oracle返回表的存储过程
oracle
CREATE OR REPLACE PACKAGE N_SUPPLIER_TYPE_APR IS
TYPE DataTable IS REF CURSOR ;
PROCEDURE Get_View( dt OUT DataTable );
END N_SUPPLIER_TYPE_APR ;
CREATE OR REPLACE PACKAGE BODY N_SUPPLIER_TYPE_APR IS
PROCEDURE Get_View( dt OUT DataTable )
IS
BEGIN
OPEN dt FOR
SELECT * FROM n_supplier_type;
END Get_View;
END N_SUPPLIER_TYPE_APR ;
c#
protected static string connectionString = "Data Source=oradb;User Id=app;Password=password;";
public static DataTable RunProcedure(string storedProcName)
{
using (OracleConnection connection = new OracleConnection(connectionString))
{
connection.Open();
OracleCommand command = new OracleCommand(storedProcName, connection);
command.CommandType = CommandType.StoredProcedure;
command.Parameters.Add("dt", OracleType.Cursor).Direction = ParameterDirection.Output;
OracleDataAdapter DataAdapter = new OracleDataAdapter(command);
DataTable dt = new DataTable();
DataAdapter.Fill(dt);
connection.Close();
return dt;
}
}