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 | +---------------------------------+ |