Home Tutorial Php Sql MySQL BEGIN

 
 

MySQL BEGIN
Posted on: December 9, 2010 at 12:00 AM
This example illustrates how to use the BEGIN keyword, when we create function.

MySQL BEGIN

This example illustrates how to use the BEGIN keyword, when we create function.

In this example we create a table 't2' and function 'f1' which return integer. Now we start to insert value in the table but before insertion we execute a BEGIN command which return the value which is inserting in the table.

In the below query we execute a query for create table, create function, select function and select table and the output display in the table.

 

 

Query

 

CREATE TABLE t2 (c1 INT);
 
Query

 

DELIMITER //
  CREATE FUNCTION f1(p1 INT) RETURNS INT
  BEGIN
  INSERT INTO t2 VALUES (p1);
  RETURN p1;
  END //
DELIMITER ;

 

Query

 

select f1(4);
 

 

Output

 

+-------+
| f1(4) |
+-------+
| 4     |
+-------+

 

Query

 

select * from t2;
 
Output

 

+------+
| c1   |
+------+
| 4    |
+------+

 

Related Tags for MySQL BEGIN:


Ask Questions?

If you are facing any programming issue, such as compilation errors or not able to find the code you are looking for.

Ask your questions, our development team will try to give answers to your questions.