Mysql 具有空值的存储过程搜索
我对供应商搜索的查询是Mysql 具有空值的存储过程搜索,mysql,Mysql,我对供应商搜索的查询是 CREATE DEFINER=`root`@`localhost` PROCEDURE `supplier_Search`(in strLedgerName varchar(255),in strAddress varchar(255), in inPhoneNo int(45), in inMobNo int(45), in strPriceLevel varchar(255),in strCountry varchar(255),in strState
CREATE DEFINER=`root`@`localhost` PROCEDURE `supplier_Search`(in strLedgerName varchar(255),in strAddress varchar(255),
in inPhoneNo int(45), in inMobNo int(45), in strPriceLevel varchar(255),in strCountry varchar(255),in strState varchar(255))
BEGIN
if inPhoneNo = '' then SET inPhoneNo =Null ;end if;
if inMobNo = '' then SET inMobNo =Null ;end if;
if strLedgerName ='' then SET strLedgerName = Null; end if;
if strAddress ='' then set strAddress = null; end if;
if strPriceLevel = '' then set strPriceLevel = null; end if;
if strCountry = '' then set strCountry = null; end if;
if strState = '' then set strState = null; end if;
select ledgerName,address, phoneNo , mobNo ,priceLevel,stateName, CountryName from
(
select joined_ab.ledgerName,joined_ab.address ,joined_ab.phoneNo, joined_ab.mobNo ,joined_ab.priceLevel,c.countryName,joined_ab.stateId
from (select a.ledgerName, a.address , a.phoneNo , a.mobNo ,b.priceLevel,
a.countryId,a.stateId from tbl_ledger as a inner join tbl_price_level as b on a.pricingLevelId =b.priceLevelId)
as joined_ab inner join tbl_country as c on joined_ab.countryId = c.countryId
) as joined_abc inner join tbl_state
as d on joined_abc.stateId = d.stateId
where((strLedgerName is null or joined_abc.ledgerName LIKE concat(strLedgerName,"%"))
and(strAddress is null or address LIKE concat(strAddress ,"%"))
and(inPhoneNo is Null or phoneNo lIke concat(inPhoneNo , "%"))
and (strPriceLevel is null or priceLevel Like concat(strPriceLevel,"%"))
and(inMobNo is Null or mobNo Like concat(inMobNo , "%"))
and(strCountry is null or CountryName LikE concat(strCountry,"%"))
and(strState is null or StateName LikE concat(strState,"%")));
END
我希望在传递一个或多个值时获得输出。
但问题是当我没有传递mobileNo或phoneNo的值并执行错误时
call db_account.supplier_Search('1', '', '', '', '', '', '')
Error Code: 1366. Incorrect integer value: '' for column 'inPhoneNo' at row 1 0.000 sec
问题是由于您将整数值传递为“” SQL不知道整数的类型是什么;尝试设置0或NULL 环境向您建议问题所在:您使用“”作为整数值,SQL不知道是哪种类型的整数;尝试设置0或NULL。如果问题不在调用操作中,则必须更改过程主体中比较数据的方式: 如果inPhoneNo='',则设置inPhoneNo=Null;如果结束
是否可以使用
null
值调用thw过程,如call db\u account.supplier\u Search('1','null,null,null,null,null)
可以。不是吗?结果是一样的吗?对不起,我现在注意到你提到mysql。。。我使用sql server进行筛选。。。。在任何情况下,我都会尝试转到第1行并更改为另一个值:如果调用者中的值为“否”,则它必须位于sp正文中,您可以将整数与空字符串(“”)进行比较。请给出更多提示?结果是一样的吗?你现在的问题是什么?您是否尝试将所有整数的if close更改为其他值(例如,如果inPhoneNo=-1,则设置inPhoneNo=Null;end if;)?您是否尝试将call语句更改为类似call db_account.supplier_Search('1',''.-1,-1','','','')?