How to correctly use delimiter in a MySQL stored procedure and insert values?

MySQLMySQLi Database

Let us first create a table −

mysql> create table DemoTable2028
   -> (
   -> StudentFirstName varchar(20),
   -> StudentLastName varchar(20)
   -> );
Query OK, 0 rows affected (0.87 sec)

Here is the query to create a stored procedure and insert values (using delimiter correctly) −

mysql> delimiter //
mysql> create procedure insert_name(in fname varchar(20),in lname varchar(20))
   -> begin
   -> insert into DemoTable2028 values(fname,lname);
   -> end
   -> //
Query OK, 0 rows affected (0.17 sec)
mysql> delimiter ;

Call the stored procedure using CALL command −

mysql> call insert_name('Chris','Brown');
Query OK, 1 row affected (0.17 sec)

Display all records from the table using select statement −

mysql> select *from DemoTable2028;

This will produce the following output −

+------------------+-----------------+
| StudentFirstName | StudentLastName |
+------------------+-----------------+
| Chris            | Brown           |
+------------------+-----------------+
1 row in set (0.00 sec)
raja
Published on 06-Apr-2020 17:07:42
Advertisements