Get database name from a query implemented in a MySQL Stored Procedure?

MySQLMySQLi Database

To get the database name, use the below given syntax −

select database();

Let us implement the above syntax in the stored procedure −

mysql> delimiter //
mysql> create procedure get_procedure_database_name()
   -> begin
   -> select concat('The database name=',database());
   -> end
   -> //
Query OK, 0 rows affected (0.34 sec)
mysql> delimiter ;

Now you can call a stored procedure using CALL command −

mysql> call get_procedure_database_name();

This will produce the following output −

+-----------------------------------------+
| concat('The database name=',database()) |
+-----------------------------------------+
| The database name=web                   |
+-----------------------------------------+
1 row in set (0.05 sec)
Query OK, 0 rows affected (0.08 sec)
raja
Published on 18-Dec-2019 06:07:21
Advertisements