c# 讀取Oracle Function

來源:互聯網
上載者:User
     #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;
         * /
         
         */

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.