ORACLE segment:
First, create a PACKAGE and package body in ORACLE, and define the function and the returned result set of the stored procedure.
1: Create a PACKAGE:
Create or replace package SCOTT. pk_wt
Is
Type mytype is ref cursor;
Procedure p_wt (mycs out mytype );
Function f_get (str in varchar2)
Return varchar2;
End;
/
Note: PACKAGE is just a declaration. Here we define a stored procedure to return a collection and a function to return a string.
2: Create a package body:
Create or replace package body scott. pk_wt
Is
Procedure p_wt (mycs out mytype)
Is
Begin
Open mycs for select * from test;
End p_wt;
Function f_get (str varchar2)
Return varchar2
Is
Str_temp varchar2 (100): = good luck !;
Begin
Str_temp: = str_temp | str;
Return str_temp;
End f_get;
End pk_wt;
/
Note: here, the creation of the package body is a specific description and use, and how will it be implemented ..
C # section:
In C #, the code is divided into two parts: Using Functions and using result sets.
Define a connection and get it from WEBCONFIG:
Private OracleConnection orcn = new OracleConnection (System. Configuration. ConfigurationSettings. deleettings ["scott"]);
C # Call ORACLE functions:
OracleCommand cmd = new OracleCommand ("pk_wt.f_get", orcn );
Cmd. CommandType = CommandType. StoredProcedure;
OracleParameter p1 = new OracleParameter ("str", OracleType. VarChar, 10 );
P1.Direction = System. Data. ParameterDirection. Input;
P1.Value = this. TextBox1.Text;
OracleParameter p2 = new OracleParameter ("result", OracleType. VarChar, 100 );
P2.Direction = System. Data. ParameterDirection. ReturnValue;
Cmd. Parameters. Add (p1 );
Cmd. Parameters. Add (p2 );
Orcn. Open ();
Cmd. ExecuteNonQuery ();
Orcn. Close ();
This. Button_function.Text = p2.Value. ToString ();
The RESULT is the return variable of the system-defined function. Note that the return type of the function parameter must be specified, and the return type of the COMMAND type must also be specified, in addition, there is no difference with General stored procedures.
C # Call the ORACLE return result set:
OracleCommand cmd = new OracleCommand ("pk_wt.p_wt", orcn );
Cmd. CommandType = CommandType. StoredProcedure;
OracleParameter p1 = new OracleParameter ("mycs", OracleType. Cursor );
P1.Direction = System. Data. ParameterDirection. Output;
Cmd. Parameters. Add (p1 );
OracleDataAdapter da = new OracleDataAdapter (cmd );
DataSet ds = new DataSet ();
Da. Fill (ds, "test ");
This. DataGrid1.DataSource = ds;
This. DataGrid1.DataBind ();