Uploaded by fullsun

Scalar Functions

advertisement
1. UCASE()
The UCASE() or upper case function will change the case of the string to upper case
characters.
SELECT UCASE (String);
SELECT UCASE ("Welcome to Javatpoint") AS UpperCase_String;
SELECT ID, Name, Age, UCASE (Address) AS Address_UpperCase, Salary
FROM customers;
2. LCASE()
The lower case function will change the case of the string to lower case characters.
Here, the string can also be passed as a parameter or the table's column name,
which contains the string, can also be passed as a parameter to the LCASE ()
function.
SELECT LCASE (String);
SELECT LCASE (ColumnName) FROM TableName;
SELECT LCASE ("WELCOME TO JAVATPOINT") AS LowerCase_String;
SELECT ID, LCASE (Name) AS NameLowerCase, Age, Address, Salary
FROM customers;
3. MID()
MID () function is used to extract substrings from the table's column, which contain
values of string type.
SELECT MID (string, start, length);
String: contains the entire string from which we want to extract a specific portion
of the string.
Starting index: The integer value present in the starting index decides where the
characters in the string are to be extracted from the beginning or end of the string.
Length: The integer value present in the length field tells the count of characters
to be extracted from the string. If the length is not specified, then the entire string
will be extracted.
SELECT MID (ColumnName, start, length) FROM TableName;
SELECT MID ("Welcome to the world of databases", 16, 18) AS Substring;
- Here, the MID () function with the three parameters: 'Welcome to the world of
databases', 16, 18 is passed as a parameter to the SELECT query to print the
substring starting with the index 16 and contains 18 characters. 'Substring' is an
alias.
-
You will get the following output: world of databases
4. LENGTH()
LENGTH () function returns the length of the string in the column.
SELECT LENGTH (String);
SELECT LENGTH (ColumnName) FROM TableName;
SELECT LENGTH ("Welcome to the world of databases") AS LengthOfString; = 33
SELECT ID, LENGTH (Name) AS LengthOfName, Age, Address, Salary
FROM customers;
5. ROUND()
The ROUND () function is used to round a numeric column to the number of
decimals specified.
SELECT ROUND (NumericValue, Decimals);
SELECT ROUND (ColumnName, Decimals) FROM TableName;
SELECT ROUND (18000.44444, 2) AS RoundedValue; = 18000.44
SELECT ROUND (18000.44444, 0) AS RoundedValue; = 18000
6. NOW()
NOW () function returns the current system' date and time.
SELECT NOW ();
SELECT NOW () FROM TableName;
SELECT NOW () AS CurrentDatenTime;
7. FORMAT()
The FORMAT () function is used to format how a column is to be displayed.
SELECT FORMAT (Value, Decimal);
SELECT FORMAT (ColumnName, Decimal) FROM TableName;
SELECT FORMAT (6789.6789, 2) AS Formatted_Number; = 6,789.68
SELECT ID, Name, Age, Address, FORMAT (Salary / 0.5, 2) AS FormattedSalary (Ta
bleName)
FROM customers;
Download