Oracle獲取SP的參數

本文介绍了一种通过存储过程(SP)名称获取其参数列表的方法。使用Oracle数据库的all_arguments视图,结合具体的所有者和对象名称,可以有效地检索出SP的所有参数及其位置信息。文章提供了一个具体的C#实现示例,展示了如何利用OracleHelper类库执行SQL查询并返回参数列表。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

--根據SP的名字取SP的參數列表
 SELECT argument_name, position - 1
    FROM all_arguments
   WHERE owner = 'MES1' AND object_name = 'QUERY'
ORDER BY sequence

 

        /// <summary>
        /// 根據SP的名字取SP的參數列表;
        /// </summary>
        /// <param name="strSPName"></param>
        /// <returns></returns>
        public static DataTable GetSPPataList(string strSPName)
        {
            DataTable dtTemp = new DataTable();
            string strConString = System.Web.HttpContext.Current.Session["conString"].ToString();
            string strSQL = "SELECT argument_name, position-1                      " +
                            "FROM all_arguments                                    " +
                            "WHERE owner = 'MES1' AND object_name = :object_name   " +
                            "ORDER BY sequence                                     ";
            OracleParameter[] oraParas = new OracleParameter[]{
                    new OracleParameter(":object_name",strSPName.ToUpper())
            };
            dtTemp = DBHelper.OracleHelper.ExecuteDataTable(strConString, CommandType.Text, strSQL, oraParas);

            return dtTemp;
        }

 

 

 public static System.Data.DataTable ExecuteDataTable(string connectionString, CommandType cmdType, string cmdText, params OracleParameter[] commandParameters)
        {
            //Create the command and connection
            OracleCommand cmd = new OracleCommand();
            OracleDataAdapter adp=new OracleDataAdapter();
            OracleConnection conn = new OracleConnection(connectionString);

            try
            {
                //Prepare the command to execute
                PrepareCommand(adp,cmd, conn, null, cmdType, cmdText, commandParameters);

                //Execute the query, stating that the connection should close when the resulting datareader has been read
                DataTable dtTemp = new DataTable();
                adp.Fill(dtTemp);
                cmd.Parameters.Clear();
                conn.Dispose();
                return dtTemp;
            }
            catch
            {
                //If an error occurs close the connection as the reader will not be used and we expect it to close the connection
                conn.Close();
                throw;
            }
        }

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值