- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
What is the usage of “@” symbol in MySQL stored procedure?
The @ symbol in a stored procedure can be used for user-defined session variables. Let us first create a table −
mysql> create table DemoTable ( StudentName varchar(50) ); Query OK, 0 rows affected (1.30 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable values('John Smith'); Query OK, 1 row affected (1.00 sec) mysql> insert into DemoTable values('John Doe'); Query OK, 1 row affected (0.19 sec) mysql> insert into DemoTable values('Chris Brown'); Query OK, 1 row affected (0.53 sec)
Display all records from the table using select statement −
mysql> select *from DemoTable;
This will produce the following output −
+-------------+ | StudentName | +-------------+ | John Smith | | John Doe | | Chris Brown | +-------------+ 3 rows in set (0.00 sec)
Let us now create a stored procedure to calculate the number of records from DemoTable −
mysql> DELIMITER // mysql> create procedure `Demo_Of_@Symbol`() BEGIN select count(*) into @numberOfRecords from DemoTable; END // Query OK, 0 rows affected (0.33 sec) mysql> DELIMITER ;
Following is the query to call the stored procedure using CALL command −
mysql> call `Demo_Of_@Symbol`(); Query OK, 1 row affected (0.00 sec)
Let us now see the usage of the @symbol −
mysql> select @numberOfRecords;
This will produce the following output −
+------------------+ | @numberOfRecords | +------------------+ | 3 | +------------------+ 1 row in set (0.00 sec)
Advertisements