在线时间:8:00-16:00
迪恩网络APP
随时随地掌握行业动态
扫描二维码
关注迪恩网络微信公众号
1.不返回结果集,有输入,输出参数 /// <summary> /// 执行存储过程 /// </summary> /// <param name="storedProcName">存储过程名</param> /// <param name="sql">执行的sql语句</param> /// <param name="sql2">执行的sql语句2</param> /// <returns></returns> public static bool RunProcedure(string storedProcName, string sql, string sql2) { using (OracleConnection connection = new OracleConnection(connectionString)) { connection.Open(); OracleCommand sqlCmd = new OracleCommand(storedProcName, connection); int state =0; OracleParameter[] paras ={ new OracleParameter("p_sql",sql), new OracleParameter("p_sql2",sql2), new OracleParameter("p_state",state) //返回值 0表示失败 1表示成功 }; paras[2].Direction = ParameterDirection.Output; sqlCmd.Parameters.AddRange(paras); sqlCmd.CommandType = CommandType.StoredProcedure;//设置 使用存储过程 sqlCmd.ExecuteNonQuery(); connection.Close(); state = Convert.ToInt32(paras[2].Value); return state == 1 ? true : false; } } create or replace procedure TCZ_Operation begin execute immediate p_sql; --执行sql语句
2.返回结果集有输入输出参数 /// <summary> /// 执行存储过程 /// </summary> /// <param name="storedProcName">存储过程名</param> /// <param name="TableName">表名</param> /// <param name="strWhere">查询条件</param> /// <param name="orderColumn">排序的列</param> /// <param name="orderStyle">排序方式</param> /// <param name="pageIndex">当前页</param> /// <param name="pageSize">每页显示记录条数</param> /// <param name="rowCount">总记录数</param> /// <param name="pageCount">总页数</param> /// <returns></returns> public static DataSet RunProcedure(string storedProcName, string TableName, string strWhere, string orderColumn, string orderStyle, int pageIndex, int pageSize, out int rowCount, out int pageCount) { using (OracleConnection connection = new OracleConnection(connectionString)) { DataSet dataSet = new DataSet(); connection.Open(); OracleDataAdapter sqlDA = new OracleDataAdapter(storedProcName, connection); rowCount = 0; pageCount = 0; OracleParameter[] paras ={ new OracleParameter("p_tableName",TableName), new OracleParameter("p_strWhere",strWhere), new OracleParameter("p_orderColumn",orderColumn), new OracleParameter("p_orderStyle",orderStyle), new OracleParameter("p_curPage",pageIndex), new OracleParameter("p_pageSize",pageSize), new OracleParameter("p_totalRecords",rowCount), new OracleParameter("p_totalPages",pageCount), new OracleParameter("v_cur", OracleType.Cursor) //返回的游标 }; paras[6].Direction = ParameterDirection.Output; paras[7].Direction = ParameterDirection.Output; paras[8].Direction = ParameterDirection.Output; sqlDA.SelectCommand.Parameters.AddRange(paras); sqlDA.SelectCommand.CommandType = CommandType.StoredProcedure;//设置 使用存储过程 sqlDA.Fill(dataSet); connection.Close(); rowCount = Convert.ToInt32(paras[6].Value); pageCount = Convert.ToInt32(paras[7].Value); return dataSet; } } CREATE OR REPLACE PACKAGE pkg_query AS TYPE cur_query IS REF CURSOR;
create or replace procedure Sp_GetPageList is --验证页面记录大小 --根据页大小计算总页数 --验证页号 --实现分页查询
|
2023-10-27
2022-08-15
2022-08-17
2022-09-23
2022-08-13
请发表评论