Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • Databases
  • SQL
  • MySQL
  • PostgreSQL
  • PL/SQL
  • MongoDB
  • SQL Cheat Sheet
  • SQL Interview Questions
  • MySQL Interview Questions
  • PL/SQL Interview Questions
  • Learn SQL and Database
Open In App
Next Article:
SQL | Date Functions (Set-2)
Next article icon

Categories of SQL Functions

Last Updated : 28 Aug, 2024
Comments
Improve
Suggest changes
Like Article
Like
Report

SQL functions are powerful tools that help streamline queries, perform operations, and manipulate data efficiently. They are essential for handling various tasks within SQL queries and database management.

Functions in SQL can be broadly categorized into predefined (built-in) functions and user-defined functions. In this article, We will learn about the Categories of SQL Functions in detail with examples and so on.

Categories of Functions

Some of these categories of SQL functions are explained below. 

  1. Single_row_function
  2. Aggregate_function
  3. Analytic_function
  4. Model_function
  5. User_defined_function
  6. Scalar functions

Single Row Function

Single-row functions are those functions that return a single result row for each row of the queried table or view. This function exists in Select lists, WHERE clause, START WITH, CONNECT BY clause, and HAVING clause. 

  • Numeric_functions
  • Character_function
  • Data_mining_function
  • Datetime_functions
  • Conversion_function
  • Collection_function
  • XML_function

1. Aggregate Function

While using Aggregate function it will returns single row result based on group of rows, instead of single rows.Aggregate function appears in Select lists and ORDER BY and HAVING clause.They are usually used with GROUP BY clause and SELECT Statements. 

If we use GROUP BY clause, then Oracle applies aggregate function in the select list to all the rows in the queried table or view. 

All the Aggregate functions except GROUPING and COUNT(*) ignores null values. You can also use NVL function in the argument to an aggregate function to substitute a value in place of null. 
You can also nest aggregate functions.

For example:- 

SELECT AVG(MAX(salary) 
FROM employees
GROUP BY department_id

AVG(MAX(salary))
----------------
10925

Most frequently used Aggregate functions are AVG, COUNT, DENSE_RANK, MAX, MIN, RANK, SUM. 

2. Analytic Function

Analytic function calculate aggregate value based on group of rows.Difference between Analytic function and Aggregate function is they return multiple rows for each group. The group of rows is termed as window and it is defined by analytic_clause. 

Analytic function are the last set of operations performed in a query except the final ORDER BY clause. 

  • Analytic_clause
  • Query_partition_clause
  • Order_by_clause
  • Windowing_clause

3. Model Function

Within SELECT statements, Model Functions can be used with model_clause. 

Model Functions are: 

  • CV
  • Iteration_Number
  • Pesentnnv
  • Presentv
  • Previous

4. User Defined Function

You can use User defined functions in PL/SQL or Java to provide functionality that is not available in SQL or SQL built in functions. SQL functions and User defined functions can be appear anywhere, that is, wherever an expression occur. 

For example, It can be used in: 

  • Select list of SELECT statement.
  • Condition of WHERE clause.
  • CONNECT BY, ORDER BY, START WITH and GROUP BY
  • The VALUES clause of INSERT statement.
  • The SET clause of UPDATE statement. 

Basically we use CREATE Function to create User defined functions in SQL. 

5. Scalar Function

You can use scalar functions in SQL to return a single value, based on the input value. 

Input: SELECT UCASE(geeksforgeeks) ;
Output: GEEKSFORGEEKS

Most frequently used Scalar functions are UCASE() to convert a field to upper case, LCASE() to convert a field to lower case, LEN() to find the length of a text field, ROUND() to round the number of decimals specified, NOW() to find the current system date and time. 

Conclusion

SQL functions, whether predefined or user-defined, play a crucial role in data manipulation and query optimization. Predefined functions provide a robust set of tools for common operations, while user-defined functions offer the flexibility to address specific needs and complex logic.



Next Article
SQL | Date Functions (Set-2)

S

ShubhamMaurya3
Improve
Article Tags :
  • Databases
  • DBMS
  • SQL
  • DBMS-SQL
  • SQL-Functions

Similar Reads

  • SQL Aggregate functions
    SQL Aggregate Functions are used to perform calculations on a set of rows and return a single value. These functions are particularly useful when we need to summarize, analyze, or group large datasets in SQL databases. Whether you're working with sales data, employee records, or product inventories,
    4 min read
  • SQL | Date Functions (Set-2)
    SQL Date Functions are powerful tools that allow users to manipulate, extract , and format date and time values within SQL databases. These functions simplify handling temporal data, making them indispensable for tasks like calculating intervals, extracting year or month values, and formatting dates
    5 min read
  • SQL | Date Functions (Set-1)
    SQL Date Functions are essential for managing and manipulating date and time values in SQL databases. They provide tools to perform operations such as calculating date differences, retrieving current dates and times and formatting dates. From tracking sales trends to calculating project deadlines, w
    5 min read
  • PL/SQL Aggregate Function
    In PL/SQL, aggregate functions play an important role in summarizing and analyzing data from large datasets. These built-in SQL functions perform calculations on a set of values and return a single result, making them invaluable for tasks like calculating totals, averages, and identifying the highes
    6 min read
  • Characteristics of SQL
    Structured Query Language (SQL) is a standard language to write queries. It was developed under R Project by IBM. SQL has a basic grammar and syntax. It was declared as a standard language to use by American Standard National Institute(ANSI) and International Standard Organization(ISO). The function
    2 min read
  • SQLite DATE Function
    In SQLite database management the DATE() function is useful for handling date and time data very effectively. This function fasts the extraction of the date part from a datetime expression or conversion of a text representation of a date in date format. In this article, we will learn about the DATE(
    4 min read
  • Conversion Function in SQL
    In SQL data type conversion is important for effective database management and accurate query results. Data type conversion ensures that data from different sources or columns can be correctly interpreted and manipulated, especially when dealing with different formats like numbers, text, dates, and
    5 min read
  • MySQL Datatype Functions
    MySQL datatype functions can therefore be described as crucial elements in data processing in databases. These functions enable operations that can translate, alter and verify if basic data types such as string, number, date and binary data are sane. Due to the extent of the provided functionalities
    4 min read
  • MySQL Aggregate Function
    MySQL Aggregate Functions are used to calculate values from multiple rows and return a single result, helping in summarizing and analyzing data. They include functions for counting, summing, averaging, and finding maximum or minimum values, often used with the GROUP BY clause. In this article, we wi
    3 min read
  • COT() Function in MySQL
    COT() function : This function in MySQL is used to return the cotangent of a specified number. If the specified number is 0, an error or NULL will be returned. In a right triangle, the cotangent of an angle is the length of it's adjacent side divided by the length of the opposite side. Similarly, th
    1 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences