Oracle 查询多个数据
<MyCommand Name="LoadDataSet" Database="DataBase" CommandType="Text"> <Parameters> <Parameter Name="cur1" Type="RefCursor" Direction="Output" /> <Parameter Name="cur2" Type="RefCursor" Direction="Output" /> <Parameter Name="Sysid" Type="Int32" Direction="Output" /> </Parameters> <CommandText><![CDATA[ begin OPEN :cur1 FOR SELECT * FROM Table1; OPEN :cur2 For Select count(1) FROM Table2; Select count(1) into :Sysid FROM Table3; end; ]]></CommandText> </MyCommand>
foreach (var p in mycommand.Parameters.FindAll(x=>x.ParamType != "RefCursor")) { //参数赋值后,不在语句中使用就会报 ORA-01006: 绑定变量不存在 if (command.CommandType == CommandType.Text && !command.CommandText.Contains($":{p.ParamName}")) { continue; } //var par = new Oracle.ManagedDataAccess.Client.OracleParameter(p.ParamName,OracleDbType.Varchar2,System.Data.ParameterDirection.Input); var par = new Oracle.ManagedDataAccess.Client.OracleParameter(); par.ParameterName = p.ParamName; par.Value = param.GetPropertyValue(p.ParamName); if (!string.IsNullOrEmpty(p.ParamType) && Enum.IsDefined(typeof(OracleDbType), p.ParamType)) { OracleDbType enumItem = (OracleDbType)Enum.Parse(typeof(OracleDbType), p.ParamType); par.OracleDbType = enumItem; } if (!string.IsNullOrEmpty(p.ParamDirection) && Enum.IsDefined(typeof(ParameterDirection), p.ParamDirection)) { ParameterDirection direction = (ParameterDirection)Enum.Parse(typeof(ParameterDirection), p.ParamDirection); par.Direction = direction; } command.Parameters.Add(par); } foreach (var p in mycommand.Parameters.FindAll(x => x.ParamType == "RefCursor")) { command.Parameters.Add(p.ParamName, OracleDbType.RefCursor, ParameterDirection.Output); } OracleDataAdapter adapter = new OracleDataAdapter(); adapter.SelectCommand = command; DataSet ds = new DataSet(); adapter.Fill(ds); //command.Parameters.Clear(); Dictionary<string, object> dic = new Dictionary<string, object>(); foreach (var p in mycommand.Parameters.FindAll(x => x.ParamDirection == ParameterDirection.Output.ToString() && x.ParamType != "RefCursor")) { dic.Add(p.ParamName, command.Parameters[p.ParamName].Value); if (p.ParamType.Contains("Int")) { param.SetPropertyValue(p.ParamName, Convert.ToInt32(command.Parameters[p.ParamName].Value.ToString())); continue; } param.SetPropertyValue(p.ParamName, command.Parameters[p.ParamName].Value); }