Profile Picture
Written ByMd Tanveer

SQL Functions

SQL has some builtin functions (Mainly Numeric, String and Date/Time) which can be used to manipulate data during fetch or insertion. The concept of those functions is same as function in any programming language. The function will accept parameters and return some value. We will explore POW, CURRENT_DATE, ADDATE, SUBDATE, DATEDIF, ROUND, FORMAT, FLOOR, CEILING, TRUNCATE, UPPER, CONCAT, LENGTH, LEFT, MID, IF,

Coding
222
Nov 15, 2021 @ 12:24 PM

Important note

In SQL it is required that there should not be any space between the name of the function and the parenthesis. So function POW(3, 2) is different than POW (3, 2) as there is a space in the second function. The first one will work but the second one will throw an error

ROUND()

To round or truncate number. It takes one argument and round up or down a floating point number to nearest integer.

ROUND(55.6)

56
ROUND(55.4)

55
ROUND(55.5)

56

ROUND() (With 2 arguments)

You have the option to choose how many decimal points you would like to have in the return value. The second parameters indicates the number of decimal points you want to have.

ROUND(55.0006, 2)

55.01

FORMAT()

This function is used to format a number with commas to make any big number more readable. Just be cautious that the return value will be a String not a number as it will have comma(s)  in between the number.

FORMAT(10000.00002, 2)

10,000.01

POW()

It means the power. So if you want to put 2 to the power 3 then the function will be:

POW(3, 2)

3^2 = 9

CURDATE()

This function takes no argument. It will return the current date based on your server’s time zone. The format will be YYYY-MM-DD.

SELECT CURDATE();

2021-11-15