今天有一段代码,先是用程序实现。
闲来无聊,又用存储过程实现了一次。
程序中实现。
/// <summary> /// 根据区域和用户名获取可访问的国家 /// </summary> public DataTable GetCountry(string area,string user) { try { NHibernate.Engine.ISessionImplementor FactoryImpl = FrameWork.Repository.NHb.SessionBuilder.CreateSession().GetSessionImplementation(); OracleCommand cmd = new OracleCommand(); string strWhere1 = "1=1 "; string strWhere2 = "1=1 "; if (!String.IsNullOrEmpty(user)) { strWhere1 += String.Format( "and vrs.u_logname = '{0}'",user); } if (!String.IsNullOrEmpty(area)) { strWhere2 += String.Format("and cc.sales_area = '{0}'", area); } string sqlstr =String.Format( @"select distinct scg.customer_country,cc.sales_area,cc.countrye,cc.countryc from ifce.vw_rsh_user vru, ele_bill.sap_customer_general scg, shipuser.countryce cc where vru.sap_cust_no = scg.customer_number and scg.customer_country = cc.short_e and vru.u_loginid in (select column_value countryId from table(splitstr_fun((select vrs.u_loginid || ',' || vrs.agent_user_id from ifce.vw_rsh_user vrs where {0}), ','))) and {1}", strWhere1, strWhere2); cmd.Parameters.Clear(); OracleConnection conn = (OracleConnection)FactoryImpl.Connection; cmd.Connection = conn; cmd.CommandType = System.Data.CommandType.Text; cmd.CommandText = sqlstr; cmd.ExecuteNonQuery(); OracleDataAdapter da = new OracleDataAdapter(cmd); System.Data.DataSet ds = new System.Data.DataSet(); da.Fill(ds); return ds.Tables[0]; } catch (Exception e) { throw new FrameWork.THrException("Fail!", e); } }