Latest Tutorials| Questions and Answers|Ask Questions?|Site Map




Related Tutorials


 
 

Share on Google+Share on Google+

SQL Then

Advertisement
The Tutorial briefs you an example from SQL Then. To understand and grasp the example we create a function total that accept the input parameter variable a and b and returns a variable s.

SQL Then

     

The Tutorial briefs you an example from SQL Then. To understand and grasp the example we create a function total that accept the input parameter variable a and b and returns a variable s. The function contains a begin-end statement that includes the variables a,b and c. The set keyword variable c is assigned to the sum value of variable a and b. The if comparison operator evaluate the condition of variable c. If the value of variable c is less then 10. The output would print the 'add is less then 100'.

Otherwise the loop moves to the then which show you the 'add is equal or greater then 100'.

 

 

 

 

 

Create Function

DELIMITER $$
create function total (a int, b int) returns varchar(50)
begin
declare c int;
declare s varchar(50);
set c = a + b;
if c < 10 THEN 
set s = 'add is less then 100';

END IF;

RETURN s;
END $$
DELIMITER ;

Select function

Select total(10,10);

Result

+---------------------------------+
| total(10,10)                     |
+---------------------------------+
| add is equal or greater then 100 |
+---------------------------------+
Advertisements

If you enjoyed this post then why not add us on Google+? Add us to your Circles



Liked it!  Share this Tutorial


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: January 23, 2009

Related Tutorials

Discuss: SQL Then  

Post your Comment


Your Name (*) :
Your Email :
Subject (*):
Your Comment (*):
  Reload Image
 
 
Comments:0
DMCA.com