Home Tutorial Php Sql MySQL BEGIN

 
 

Share on Google+Share on Google+
MySQL BEGIN
Posted on: December 9, 2010 at 12:00 AM
Advertisement
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    |
+------+

 

Advertisement

Related Tags for MySQL BEGIN:


Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.

Posted on: December 9, 2010

Recommend the tutorial

Advertisements Advertisements
 

 

 

DMCA.com