Show List

Using built-in functions

SQL provides various built-in functions to perform operations on data stored in the database. These functions can be used to manipulate text, numeric, date and time data types. Some of the commonly used built-in functions in SQL are:

  1. String Functions:

    • LENGTH: Returns the number of characters in a string. For example, SELECT LENGTH('hello world') would return 11.
    • UPPER: Converts a string to uppercase. For example, SELECT UPPER('hello world') would return 'HELLO WORLD'.
    • LOWER: Converts a string to lowercase. For example, SELECT LOWER('HELLO WORLD') would return 'hello world'.
    • SUBSTRING: Extracts a portion of a string. For example, SELECT SUBSTRING('hello world', 1, 5) would return 'hello'.
  2. Numeric Functions:

    • SUM: Calculates the sum of values. For example, SELECT SUM(column_name) would return the sum of all values in the column_name.
    • AVG: Calculates the average of values. For example, SELECT AVG(column_name) would return the average of all values in the column_name.
    • MAX: Returns the maximum value. For example, SELECT MAX(column_name) would return the maximum value in the column_name.
    • MIN: Returns the minimum value. For example, SELECT MIN(column_name) would return the minimum value in the column_name.
  3. Date and Time Functions:

    • CURRENT_DATE: Returns the current date. For example, SELECT CURRENT_DATE would return the current date.
    • CURRENT_TIME: Returns the current time. For example, SELECT CURRENT_TIME would return the current time.
    • CURRENT_TIMESTAMP: Returns the current date and time. For example, SELECT CURRENT_TIMESTAMP would return the current date and time.
    • EXTRACT: Extracts a portion of a date or time value. For example, SELECT EXTRACT(YEAR FROM date_column) would return the year from the date_column.

These are just a few examples of the built-in functions in SQL. Depending on the database management system you are using, there may be additional functions available.


    Leave a Comment


  • captcha text