MySQL存储过程将执行但条件不起作用。有人可以解决这个问题吗?
空值未检查or
条件。是否需要替换or
?
DELIMITER $$
CREATE DEFINER=`rebar`@`%` PROCEDURE `SearchInProgress`(
ClientID bigint,
GCName varchar(250),
TeamID int,
USPMID Bigint,
JobReceivedDate datetime,
importanceID Bigint
)
begin
select * from jobdetails
where
(clientid = ClientID or ClientID = "") and
(GCName = GCName or GCName ="") and
(TeamID = TeamID or TeamID ="") and
(ReceivedDate = JobReceivedDate or JobReceivedDate = "") and
(ImportanceID = importanceID or importanceID = "") and
(JobID in (select jobid from JobCoordinatorDetails where USProjectManagerID = USPMID) );
end
答案 0 :(得分:0)
我认为它可能是括号
此(clientid = ClientID or ClientID = "")
可以像这样编写
(clientid = ClientID) OR (ClientID = "" )
它的想法。我可能错了
答案 1 :(得分:0)
DELIMITER $$
DROP PROCEDURE if exists SearchInProgress $$
CREATE PROCEDURE `SearchInProgress`(
aclientID bigint,
aGCName varchar(250),
aTeamID int,
aUSProjectManagerID bigint,
aReceivedDate datetime,
aImportanceID bigint
)
begin
select * from jobdetails
where
(clientid = aclientID or aclientID = '') and
(GCName = aGCName or aGCName = '') and
(TeamID = aTeamID or aTeamID = '') and
(ReceivedDate = aReceivedDate or aReceivedDate = '0000-00-00 00:00:00') and
(ImportanceID = aImportanceID or aImportanceID = '') and
(JobID in (select jobid
from JobCoordinatorDetails
where USProjectManagerID = aUSProjectManagerID) or aUSProjectManagerID = '')
;
end
参数名称和列名称必须不同。我已将a
添加到参数名称。
空的日期时间值替换为'0000-00-00 00:00:00':https://dev.mysql.com/doc/refman/5.7/en/datetime.html