存储过程中将忽略IS NULL和IS NOT NULL

时间:2020-06-26 02:07:06

标签: mysql stored-procedures

我正在尝试执行存储过程,但是存储过程中IS NOT NULL的查询将被忽略。这仅在存储过程中发生...当我尝试仅执行查询时,按预期方式工作。为什么会这样?

CREATE PROCEDURE `register_customer`(
    IN IDENTIFICATION_ VARCHAR(45),
    IN PHONENUM_ VARCHAR(20),
    IN TAC_ VARCHAR(6)
)
BEGIN

    DECLARE CONTINUE HANDLER FOR NOT FOUND SET @dummyVar := 1;
    
    DECLARE EXIT HANDLER FOR SQLEXCEPTION, SQLWARNING
    BEGIN
        GET DIAGNOSTICS CONDITION 1 @p1 = RETURNED_SQLSTATE, @p2 = MESSAGE_TEXT;
        select 0 as procStatus, @p2 as procMsg;
        ROLLBACK;
    END;
    
    SET autocommit=0;
    
    MyScope:BEGIN
        set @err := '';
        
        START TRANSACTION;
        
            #set @systemActivities := ACTIVITYDETAILS_;
            
            #filter
            SET @custLoginID := (SELECT id FROM customer_login WHERE identification = IDENTIFICATION_ and phonenum=PHONENUM_);
            if @custLoginID is not null then
                set @err := 'Customer Exist';
                LEAVE MyScope;
            end if;
            
            SET @tacid := (SELECT id FROM tac WHERE phonenum=PHONENUM_ AND tac=TAC_ AND verified IS NOT null);
            if @tacid is null then
                set @tacid := 'Not Verified';
                LEAVE MyScope;
            end if;
            
        COMMIT;
    END;
    
    SET autocommit=1;
    
    if @err != '' then
        select 0 as procStatus, @err as errorDesc;
    else
        select 1 as procStatus , @tacid as tacId;
    end if;

END

0 个答案:

没有答案