
- Trending Categories
Data Structure
Networking
RDBMS
Operating System
Java
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- 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)
- Related Questions & Answers
- MySQL “not a variable or NEW pseudo-variable” message. What is this error in my Stored Procedure?
- What Information is Stored in the Symbol Table?
- What is “SELECT TRUE” in MySQL?
- What is the difference between MySQL stored procedure and function?
- MySQL procedure to display a “select” statement twice
- Can we use the “.” symbol in MongoDB collection name?
- What is stored procedure and how can we create MySQL stored procedures?
- Display description of MySQL stored procedure
- MySQL “order by” inside of “group by”? Is it possible?
- In a MySQL schema, what is the meaning of “AUTO_INCREMENT=3”
- Can we use “IF NOT IN” in a MySQL procedure?
- What is the purpose and usage of “FOR UPDATE OF” clause in a COBOL-DB2 program
- What is the purpose and usage of “WHERE CURRENT OF” clause in a COBOL-DB2 program?
- What is “where 1=1” statement in MySQL?
- How can a MySQL stored procedure call another MySQL stored procedure inside it?
Advertisements