Skip to main content

Posts

Showing posts with the label sql function

Stored Function in SQL

Stored Function in SQL Function is mainly used in the case where it must return a value. Function can be called from SQL statements. You can have DML (insert,update, delete) statements in a function. Function returns 1 value only.  Mysql: Simple function to return cube CREATE FUNCTION `calcube`(`PID` INT)           RETURNS INT(11)           RETURN PID * PID * PID Function to return student division based on marks DELIMITER $$ CREATE FUNCTION resultRemark(mark1 int,mark2 int,mark3 int,mark4 int,mark5 int) RETURNS VARCHAR(50)           DETERMINISTIC BEGIN          DECLARE lvl varchar(50); DECLARE total int; DECLARE percentage double; SET total = mark1 + mark2 + mark3 + mark4 + mark5; SET percentage = (total*100)/500;          IF percentage >= 60 THEN          ...