1 由于交叉表的八个报表写在sql中了,每个报表对应sql语句有300行之多,不能定义视图,因为必须传递个参数,所以利用了存储过程实现。
首先,定义包,然后定义包体,在用.net调用生成数据集即可
.net调用oracle带参数的存储过程,返回数据集
Oracle这个复杂一些,步骤如下:
在pl/sql中首先写包的定义文件
CREATE OR REPLACE PACKAGE ZHBB AS
TYPE t_cursor IS REF CURSOR ;
Procedure ZH11 (rq IN char, io_cursor IN OUT t_cursor);
Procedure ZH12 (rq IN char, io_cursor IN OUT t_cursor);
END ZHBB;
其次写包体的定义文件
CREATE OR REPLACE PACKAGE BODY ZHBB AS
Procedure ZH11(rq IN char, io_cursor IN OUT t_cursor) IS
v_cursor t_cursor;
BEGIN
OPEN v_cursor FOR
Select * from aa where ny=rq;
io_cursor := v_cursor;
END ZH11;
Procedure ZH12 (rq IN char, io_cursor IN OUT t_cursor) IS
。。。。。
END ZH12;
.net调用方法:
public static DataTable GetDataTable(string PackageName,string ProName,string connString,string rq)
{
connString=” Provider= MSDAORA.1;User ID=xx;Data Source=xx;Password=xx;”
//定义下新的链接方法,因为原来的驱动"OraOLEDB.Oracle"不能满足需求,设置为"MSDAORA.1"
OleDbConnection raclecon = new OleDbConnection(connString);
Oraclecon.Open();
OleDbCommand cmd = new OleDbCommand("{Call "+ PackageName +"."+ ProName +"(?, {resultset 0, io_cursor} )}", Oraclecon);
cmd.Connection = Oraclecon;
cmd.Parameters.Add("rq", OleDbType.VarChar, 8).Value = ""+ rq +"";
OleDbDataAdapter da = new OleDbDataAdapter(cmd);
DataTable dt = new DataTable();
//DataSet ds = new DataSet();
da.Fill(dt);
Oraclecon.Close();
Oraclecon.Dispose();
return dt;
}
}