• c# 讀取Oracle Function


         #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;
             * /
             
             
    */
  • 相关阅读:
    KMP算法
    214. Shortest Palindrome
    5. Longest Palindromic Substring
    266. Palindrome Permutation
    Oracle 在not in中使用null的问题
    Oracle SQL性能优化技巧大总结
    EBS trace分析
    从SEQUENCE跳号说起
    使用WebService与Oracle EBS进行集成
    EBS xml publisher中文乱码
  • 原文地址:https://www.cnblogs.com/scottckt/p/1213393.html
Copyright © 2020-2023  润新知