Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
 
  • Functions in MySQL

    • 0
    • 1
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 586
    Comment on it

    Function is a predefined program in which we pass the parameters and it return a value. There are two types of function create function and predefined functions.

    Create function- Like other languages we can also create function in MySQL.
    Below syntax is used to create function:-

    CREATE FUNCTION function_name [ (parameter datatype [, parameter datatype]) ]
                                                //parameters are passed into the function
    
    RETURNS return_datatype    //function's datatype return the value
    
    BEGIN
    
       declaration_section  //declaration of local variables
    
       executable_section  //code for the function
    
    END;
    


    Predefined functions- Predefined are the functions which are inbuilt, it only needs to be called. There are various types of predefined functions-Aggregate function, String function, Date and Time and Control flow functions.

    1.AGGREGATE FUNCTIONS

    Functions Description
    AVG() Finds the average
    COUNT() Counts the number of rows
    MAX() returns the maximum value
    MIN() returns the minimum value
    SUM() returns the sum


    2. STRING FUNCTIONS

    Functions Description
    UCASE() Converts the text in upper case
    LCASE() Converts the text in lower case
    LEN() returns the length of text area
    TRIM() removes unwanted character
    CONCAT() concatenate two or more strings into one string


    3.DATE AND TIME FUNCTIONS

    Functions Description
    DATEDIFF() Calculates the difference between two dates
    DATE_FORMAT() formats the date into specific format
    NOW() returns the current date and time


    4. CONTROL FLOW FUNCTIONS

    Functions Description
    IF() returns the value inside this function
    IFNULL() if it is not null then returns the first argument otherwise returns the second argument
    NULLIF() if both the arguments are equal then returns null, otherwise returns the first argument

 0 Comment(s)

Sign In
                           OR                           
                           OR                           
Register

Sign up using

                           OR                           
Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: