Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>As far as I understood you question you would like to reduce the round trips to your database. This can be done by a stored procedure in the following way:</p> <p><a href="http://msdn.microsoft.com/en-us/library/ms971506.aspx#msdnorsps_topic6" rel="nofollow">http://msdn.microsoft.com/en-us/library/ms971506.aspx#msdnorsps_topic6</a></p> <p>Package header:</p> <pre><code>CREATE OR REPLACE PACKAGE SELECT_JOB_HISTORY AS TYPE T_CURSOR IS REF CURSOR; PROCEDURE GetJobHistoryByEmployeeId ( p_employee_id IN NUMBER, cur_JobHistory OUT T_CURSOR ); END SELECT_JOB_HISTORY; </code></pre> <p>Package:</p> <pre><code>CREATE OR REPLACE PACKAGE BODY SELECT_JOB_HISTORY AS PROCEDURE GetJobHistoryByEmployeeId ( p_employee_id IN NUMBER, cur_JobHistory OUT T_CURSOR ) IS BEGIN OPEN cur_JobHistory FOR SELECT * FROM JOB_HISTORY WHERE employee_id = p_employee_id; END GetJobHistoryByEmployeeId; END SELECT_JOB_HISTORY; </code></pre> <p>Client:</p> <pre><code>// create connection OracleConnection conn = new OracleConnection("Data Source=oracledb; User Id=UserID;Password=Password;"); // create the command for the stored procedure OracleCommand cmd = new OracleCommand(); cmd.Connection = conn; cmd.CommandText = "SELECT_JOB_HISTORY.GetJobHistoryByEmployeeId"; cmd.CommandType = CommandType.StoredProcedure; // add the parameters for the stored procedure including the REF CURSOR // to retrieve the result set cmd.Parameters.Add("p_employee_id", OracleType.Number).Value = 101; cmd.Parameters.Add("cur_JobHistory", OracleType.Cursor).Direction = ParameterDirection.Output; // open the connection and create the DataReader conn.Open(); OracleDataReader dr = cmd.ExecuteReader(); // output the results and close the connection. while(dr.Read()) { for(int i = 0; i &lt; dr.FieldCount; i++) Console.Write(dr[i].ToString() + ";"); Console.WriteLine(); } conn.Close(); </code></pre> <p>If you have to join these tables you can also use a normal join and split the result on the client (imho this is the way how a lot of ORMs do it).</p>
    singulars
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload