Oracle存储过程 使用游标、数组的配合查询
查询输入的门牌号码是否在标准门牌库中存在。存在则返回相应的号码。
1 public string GetValidate(){ 2 3 OracleConnection conn = ConnectOra(); 4 string retRepMphm; 5 try 6 { 7 conn.open(); 8 OracleComandType cmd=conn.CreateCommand(); 9 cmd.CommandType=Commandype.StoredProcedure; 10 cmd.CommandText=""sp_querybzdm; 11 OracleParameter[] parameters =new OracleParameter[4]; 12 parameters[0]=new OracleParameter("mplxs",OracleType.VarChar); 13 parameters[1]=new OracleParameter("bzdms",OracleType.VarChar); 14 parameters[2]=new OracleParameter("mphms",OracleType.VarChar); 15 parameters[3]=new OracleParameter("remphm",OracleType.VarChar,2000); 16 17 parameters[0].Value="大门牌"; 18 parameters[1].Value="吕岭路"; 19 parameters[2].Value="1号"; 20 parameters[3].Value=ParameterDirection.Output; 21 22 foreach(OraclePrameter parameter in parameters) 23 cmd.Parameters.Add(parameter); 24 } 25 cmd.ExecuteNonQuery(); 26 retRepMphm=parameters[3].value==null?"":parameters[3].Value.Tostring(); 27 catch(Exception){} 28 throw ex; 29 } 30 finaly{ 31 32 conn.close(); 33 } 34 35 create or replace proceduce sp_querybzdm 36 ( 37 mplxs in varchar2;----定义变量 38 bzdm in varchar2; 39 mphms in varchar2; 40 remphm out varchar2 ---输出变量 41 ) is 42 countnum number; 43 44 --游标 45 cursor curmas is 46 select regexp_substr(mphms ,'[^,]+',1,level) as we 47 from dual 48 connect by level<=length(mphms )-length(replace(mphms,','))+1 49 50 begin 51 for row_ma in curmas loop 52 begin 53 select count(*) into countnum from YW_LMP_QD where BZHM=row_mas.we ; 54 if(count(*)<>0) then 55 if str_result is not null then 56 str_result:=str_result||','|| row_ma.we 57 else 58 str_result:=row_ma.we 59 end if; 60 end if; 61 end 62 end loop; 63 if str_result is not null then 64 remphm:=rtrim(str_result,','); 65 end if 66 end
一万个小时的专注带给你是无限的可能