![Trending Articles on Technical and Non Technical topics](/images/trending_categories.jpeg)
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
Display table records from a stored procedure in MySQL
Let us first create a table −
mysql> create table DemoTable1933 ( ClientName varchar(20) ); Query OK, 0 rows affected (0.00 sec)
Insert some records in the table using insert command −
mysql> insert into DemoTable1933 values('Chris Brown'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1933 values('David Miller'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1933 values('Adam Smith'); Query OK, 1 row affected (0.00 sec) mysql> insert into DemoTable1933 values('John Doe'); Query OK, 1 row affected (0.00 sec)
Display all records from the table using select statement −
mysql> select * from DemoTable1933;
This will produce the following output −
+--------------+ | ClientName | +--------------+ | Chris Brown | | David Miller | | Adam Smith | | John Doe | +--------------+ 4 rows in set (0.00 sec)
Here is the query to create a stored procedure and set SELECT in it to display records −
mysql> delimiter // mysql> create procedure display_all_records() begin select * from DemoTable1933; end // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
Now you can call a stored procedure using call command:
mysql> call display_all_records();
This will produce the following output −
+--------------+ | ClientName | +--------------+ | Chris Brown | | David Miller | | Adam Smith | | John Doe | +--------------+ 4 rows in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
Advertisements