Incorrect number of arguments for PROCEDURE

Define procedure:



DELIMITER $$
CREATE PROCEDURE SP_Reporting(IN tablename VARCHAR(20))
proc_label:BEGIN
IF tablename IS NULL THEN
SELECT 'Null detect';
LEAVE proc_label;
END IF;

SELECT 'after';
END;
$$
DELIMITER ;


Call Procedure:



CALL SP_Reporting();


Error :




ERROR 1318 (42000): Incorrect number of arguments for PROCEDURE
cds.SP_Reporting ; expected 1, got 0




How pass var by default like SP_Reporting(IN tablename = 'default value' VARCHAR(20))



Answers

When you are making your stored procedure, you can assign a value to your input, so there is no need to pass parameters while you are calling the proc.



We usually assign NULL and for making parameters optional, we use this method.



tablename VARCHAR(20) = NULL


Your complete script:



DELIMITER $$
CREATE PROCEDURE SP_Reporting(IN tablename VARCHAR(20) = NULL)
proc_label:BEGIN
IF tablename IS NULL THEN
SELECT 'Null detect';
LEAVE proc_label;
END IF;

SELECT 'after';
END;
$$
DELIMITER ;


EDIT



MySQL is not accepting optional parameters. So one way is to pass NULL value in your stored procedure and check it with IF statement inside your proc.



DELIMITER $$
CREATE PROCEDURE SP_Reporting(IN tablename VARCHAR(20))
proc_label:BEGIN
IF tablename IS NULL THEN
-- Do something;
ELSE
-- Do something else;
END IF;
END;
$$
DELIMITER ;


Answers

You have to pass the table name in the procedure call statement like:



CALL SP_Reporting(table_name);



you can't pass default in call statement.
You can assign default value before calling the procedure.
or use OUT instead of IN as a parameter.



Answers

you miss the parameter :tablename
you should like this :
call SP_Reporting('any varchar')

or
call SP_Reporting(null)