Golang Tutorials - Learn Go Programming with Easy Step-by-Step Guides

Explore comprehensive Golang tutorials for beginners and advanced programmers. Learn Go programming with easy-to-follow, step-by-step guides, examples, and practical tips to master Go language quickly.

Scalar Functions In Sql in SQL

Scalar Functions In Sql in SQL

? Scalar Functions in SQL

Scalar functions operate on a single value and return a single value. They are used to perform calculations, manipulate strings, dates, or numbers, and return one result per input row.


Categories of Scalar Functions:

CategoryDescriptionExamples
String FunctionsManipulate text stringsUPPER(), LOWER(), LTRIM(), RTRIM(), SUBSTRING()
Numeric FunctionsPerform calculations on numeric valuesROUND(), ABS(), CEILING(), FLOOR(), POWER()
Date/Time FunctionsWork with date and time valuesGETDATE(), DATEADD(), DATEDIFF(), YEAR(), MONTH()
Conversion FunctionsConvert between data typesCAST(), CONVERT()
System FunctionsReturn system infoUSER(), DATABASE(), SESSION_USER()
Miscellaneous FunctionsOther functionsCOALESCE(), NULLIF(), ISNULL()

? Examples of Scalar Functions

String:

SELECT UPPER('hello') AS uppercase_string;   -- Returns 'HELLO'SELECT SUBSTRING('abcdef', 2, 3) AS substr;  -- Returns 'bcd'

Numeric:

SELECT ROUND(123.4567, 2) AS rounded_val;    -- Returns 123.46SELECT ABS(-10) AS absolute_val;              -- Returns 10

Date/Time:

SELECT YEAR(GETDATE()) AS current_year;      -- Returns current yearSELECT DATEADD(day, 7, GETDATE()) AS next_week; -- Adds 7 days to current date

? Notes:

  • Scalar functions are evaluated for each row in a query.

  • Using scalar functions can affect query performance if overused in large datasets.

  • Most SQL dialects support these common scalar functions with slight syntax variations.


Would you like me to list specific scalar functions for a particular SQL dialect (e.g., MySQL, SQL Server, Oracle)?

Disclaimer for AI-Generated Content:
The content provided in these tutorials is generated using artificial intelligence and is intended for educational purposes only.
html
docker
php
kubernetes
golang
mysql
postgresql
mariaDB
sql