#region 讀取Function
string sOraConnection = "Data Source=SH2.CHS.CYMMETRIK.COM;Persist Security Info=True;User ID=doc;Password=***;Unicode=True";
/// <summary>
/// 從表中讀取Function方法2
/// </summary>
private void ConnecctOracleFunctionTwo()
{
OracleConnection ocConnection = new OracleConnection(sOraConnection);
OracleCommand ocCommand = ocConnection.CreateCommand();
ocCommand.CommandText = "doc.Get_DM_OBJECT";
ocCommand.CommandType = CommandType.StoredProcedure;
ocCommand.Parameters.Add("v_id", OracleType.Number);
//注意,这里必须和PLSQL里的名字相符,否则错误。
//傳入參數的值
ocCommand.Parameters["v_id"].Value = 83;
ocCommand.Parameters["v_id"].Direction = ParameterDirection.Input;
ocCommand.Parameters.Add("v_name",OracleType.VarChar,200);
ocCommand.Parameters["v_name"].Direction = ParameterDirection.ReturnValue;
try
{
ocConnection.Open();
ocCommand.ExecuteOracleScalar();
string strRet = ocCommand.Parameters["v_name"].Value.ToString();
rtb.Text = strRet;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 從表中讀取Function方法1
/// </summary>
private void ConnecctOracleFunctionOne()
{
OracleConnection ocConnection = new OracleConnection(sOraConnection);
OracleCommand ocCommand = ocConnection.CreateCommand();
ocCommand.CommandText = " select doc.Get_DM_OBJECT(:Dob_ID) from DM_OBJECT";
ocCommand.Parameters.Add("Dob_ID", OracleType.Number);
//傳入參數的值
ocCommand.Parameters["Dob_ID"].Value = 83;
ocCommand.Parameters["Dob_ID"].Direction = ParameterDirection.Input;
try
{
ocConnection.Open();
string strRet = ocCommand.ExecuteOracleScalar().ToString();
rtb.Text = strRet;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
/* 被調用的Function
* CREATE OR REPLACE function Get_DM_OBJECT(v_id DM_OBJECT.Id%type)
* return DM_OBJECT.NAME%type
* as
* v_name DM_OBJECT.NAME%type;
* begin
* select name into v_name
* from DM_OBJECT
* where id=v_id;
* return v_name;
* exception when no_data_found
* then return '';
* end;
* /
*/
string sOraConnection = "Data Source=SH2.CHS.CYMMETRIK.COM;Persist Security Info=True;User ID=doc;Password=***;Unicode=True";
/// <summary>
/// 從表中讀取Function方法2
/// </summary>
private void ConnecctOracleFunctionTwo()
{
OracleConnection ocConnection = new OracleConnection(sOraConnection);
OracleCommand ocCommand = ocConnection.CreateCommand();
ocCommand.CommandText = "doc.Get_DM_OBJECT";
ocCommand.CommandType = CommandType.StoredProcedure;
ocCommand.Parameters.Add("v_id", OracleType.Number);
//注意,这里必须和PLSQL里的名字相符,否则错误。
//傳入參數的值
ocCommand.Parameters["v_id"].Value = 83;
ocCommand.Parameters["v_id"].Direction = ParameterDirection.Input;
ocCommand.Parameters.Add("v_name",OracleType.VarChar,200);
ocCommand.Parameters["v_name"].Direction = ParameterDirection.ReturnValue;
try
{
ocConnection.Open();
ocCommand.ExecuteOracleScalar();
string strRet = ocCommand.Parameters["v_name"].Value.ToString();
rtb.Text = strRet;
}
catch (Exception ex)
{
throw ex;
}
}
/// <summary>
/// 從表中讀取Function方法1
/// </summary>
private void ConnecctOracleFunctionOne()
{
OracleConnection ocConnection = new OracleConnection(sOraConnection);
OracleCommand ocCommand = ocConnection.CreateCommand();
ocCommand.CommandText = " select doc.Get_DM_OBJECT(:Dob_ID) from DM_OBJECT";
ocCommand.Parameters.Add("Dob_ID", OracleType.Number);
//傳入參數的值
ocCommand.Parameters["Dob_ID"].Value = 83;
ocCommand.Parameters["Dob_ID"].Direction = ParameterDirection.Input;
try
{
ocConnection.Open();
string strRet = ocCommand.ExecuteOracleScalar().ToString();
rtb.Text = strRet;
}
catch (Exception ex)
{
throw ex;
}
}
#endregion
/* 被調用的Function
* CREATE OR REPLACE function Get_DM_OBJECT(v_id DM_OBJECT.Id%type)
* return DM_OBJECT.NAME%type
* as
* v_name DM_OBJECT.NAME%type;
* begin
* select name into v_name
* from DM_OBJECT
* where id=v_id;
* return v_name;
* exception when no_data_found
* then return '';
* end;
* /
*/