0

I have create MySQL procedure having multiple IN parameters. I want to call procedure with few parameters but when I leave other fields blank it shows this error:

DELIMITER $$ 
CREATE DEFINER=itzakeed_akeed@localhost PROCEDURE ApiKez(
IN Choice VARCHAR(100), 
IN ValidKey VARCHAR(100), 
IN azid INT(5), 
IN amts FLOAT(50)
) 
BEGIN 

DECLARE GetKey VARCHAR(100); 
DECLARE Balance FLOAT; 

CASE WHEN Choice='KeyCheck' THEN 
  SELECT COUNT(id) INTO GetKey 
  FROM users 
  WHERE api_key=ValidKey;

  if key is valid
  IF GetKey=1 THEN 
    SELECT * 
    FROM users 
    WHERE key=ValidKey; 
  ELSE 
    SELECT 0; 
  END IF; 
ELSE 
  SELECT "INVALID INPUT CHOICE"; 
END CASE; 
END
$$ 
DELIMITER ;
tadman
  • 208,517
  • 23
  • 234
  • 262
  • Possible duplicate of [Is it possible to have a default parameter for a mysql stored procedure?](https://stackoverflow.com/questions/982798/is-it-possible-to-have-a-default-parameter-for-a-mysql-stored-procedure) – Madhur Bhaiya Nov 23 '18 at 18:32
  • 1
    `KEY` is a reserved word and should be surrounded by backticks https://dev.mysql.com/doc/refman/5.7/en/keywords.html – aynber Nov 23 '18 at 18:42
  • Could you please check your question and see if you think the formatting of the code could be improved by the appropriate markup. – Nigel Ren Nov 23 '18 at 18:47
  • Sir I only wanna know .If I define 5 IN parameters in procedure and call the procedure with 4 parameters blank it gives error to fill all fields .but i have to post only I parameter – Akeed Hussain Bhat Nov 23 '18 at 18:53
  • As a note, when asking questions here try and use full English words and avoid text-message style shorthand that people may not be familiar with. Auto-translation tools can also get seriously confused by these. – tadman Nov 23 '18 at 19:32
  • @AkeedHussainBhat could you share how you are calling the stored procedure? Also, if you could share the exact error faced - along with the error code – Valerian Pereira Nov 24 '18 at 06:06

1 Answers1

0

No you cannot call a procedure with less parameters than what is required. However, you can pass null or empty strings and check if a parameter has a value from withing the stored procedure.

Krish
  • 5,917
  • 2
  • 14
  • 35