Jump to content

Mysql and stored procedure


Recommended Posts

Hello. For the first time I try to understand this topic, but there are questions.
I create a test procedure
DELIMITER //
DROP procedure IF EXISTS UserExist //
 
CREATE procedure UserExist (IN UserName VARCHAR(50), out RetMsg int)
 
  BEGIN
 
    SELECT id INTO RetMsg FROM Tab WHERE user = UserName;
 
  END;
//
DELIMITER ;
 
DELIMITER //
DROP procedure IF EXISTS SomeAuth //
CREATE PROCEDURE SomeAuth (UserName VarCHAR(50))
  BEGIN
    DECLARE pid int DEFAULT 0;
    DECLARE pMSG int DEFAULT 0;
    DECLARE pFile Mediumblob;
    DECLARE IsUser VARCHAR(20);
    set IsUser ='DefVal';
    call UserExist(UserName, @pMSG);
 
    if pMSG = 0 then
      set pid = 0;
        else
      set pid = 1;
    end iF;
  select @pid, @pMSG ;
  END //
 
DELIMITER ;
call SomeAuth('xxxxxxxxxxxxxxxxx'); 

In return i have:

@pid @pMSG

<null> 20

and so, I do not understand why

pid =<nul>?

why not 0 (as default value) or 1 (as if statement).

Edited by cmh
Link to comment
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...