Scalar functions operate on a single value and return a single value. Unlike aggregate functions, they do not work on groups of rows but on individual fields and can be used in SELECT
, WHERE
, and ORDER BY
clauses.
π Tip: Scalar functions are very useful for transforming or formatting data before display or processing.
UPPER()
β Converts text to uppercaseLOWER()
β Converts text to lowercaseLENGTH()
β Returns the length of a stringROUND()
β Rounds a number to a given decimal placeNOW()
β Returns the current date and timeGETDATE()
β Returns the current system timestamp (SQL Server)CONVERT()
β Converts a value from one data type to anotherSELECT SCALAR_FUNCTION(column_name) FROM table_name WHERE condition;
1. Convert names to uppercase:
SELECT UPPER(Name) FROM Customers;
2. Round prices to 2 decimal places:
SELECT ROUND(Price, 2) FROM Products;
3. Get the current date and time:
SELECT NOW();
Scalar functions are essential for performing transformations on individual data values. Whether youβre formatting strings, rounding numbers, or manipulating dates, these functions make data presentation and filtering more efficient and readable.
β Next Step: Try combining scalar and aggregate functions to create powerful SQL queries!
Help others discover Technorank Learning by sharing your honest experience.
Your support inspires us to keep building!