The user-defined functions in SQL are like functions in any other programming language that accept parameters, perform complex calculations, and return a value. They are written to use the logic repetitively whenever required. There are two types of SQL user-defined functions:
-
- Scalar Function: As explained earlier, user-defined scalar functions return a single scalar value.
- Table Valued Functions: User-defined table-valued functions return a table as output.
- Inline: returns a table data type based on a single SELECT statement.
- Multi-statement: returns a tabular result-set but, unlike inline, multiple SELECT statements can be used inside the function body.