MySQL stored procedure parameters don't seem to work with special character @?

MySQLMySQLi Database

You cannot give MySQL stored procedure parameter with @ in the beginning. You can give @ sign in user-defined variables.

Following is the syntax −

SET @yourVariableName=yourValue;

Let us implement the above syntax to correctly place @sign −

mysql> DELIMITER //
mysql> CREATE PROCEDURE declare_Variable(IN StudentName varchar(100))
   BEGIN
      SET @Name=StudentName;
      SELECT @Name;
   END
//
Query OK, 0 rows affected (0.12 sec)
mysql> DELIMITER ;

Now you can call stored procedure with the help of CALL command −

mysql> call declare_Variable('John Smith');

This will produce the following output −

+------------+
| @Name      |
+------------+
| John Smith |
+------------+
1 row in set (0.00 sec)
Query OK, 0 rows affected, 1 warning (0.03 sec)
raja
Published on 22-Aug-2019 10:28:36
Advertisements