SQL - Advance Functions
SQL - Advance Functions
DATALENGTH(expression) -> count both ‘leading spaces’ & ‘trailing spaces’ = LEN(string) ->
count ‘leading spaces’ but not ‘trailing spaces’ ( if expression NULL, returns NULL)
LTRIM(string) -> remove leading spaces from a string > < RTRIM(string) -> remove trailing
spaces from string
TRIM( [chars FROM] string) -> removes the space character OR other specified characters from
the start or end of a string. NOTE: By default, removes leading and trailing spaces from string.
PATINDEX(%pattern_in_string%, string)
REVERSE(string)
STR(number, length, decimals) -> returns number as string (if number > length -> number will
be hidden by *) NOTE: default value of length = 10, of decimals = 0
TRANSLATE(string, characters, translations) -> returns string from the first argument after the
characters specified in the 2nd argument are translated into the characters specified in the 3rd
argument NOTE: return an error if characters and translations have different lengths
Exp: SELECT TRANSLATE(‘Monday’, ‘Mon’, ‘Sun’) -> Sunday
UNICODE(character_expression) -> returns integer value (Unicode value), for the 1st character
of the input expression
MYSQL: Query the list of CITY names from STATION that do not start with vowels and do not
end with vowels. Your result cannot contain duplicates.
select distinct city from station where city not REGEXP '^[aeiou]' and city not REGEXP '[aeiou]$'