String functions
There are a number of string functions that can be used to alter strings. A description of a few of these functions are shown below:
- The
LOWER(fieldName)
function changes the case of all characters infieldName
to lower case. - The
INITCAP(fieldName)
function changes the case of all characters infieldName
to proper case. - The
LEFT(fieldName,N)
function returns the leftN
characters of the stringfieldName
. - The
SUBSTRING(fieldName from S for N)
returnsN
characters starting from positionS
of the stringfieldName
. Note that bothfrom S
andfor N
are optional.
This exercise is part of the course
Reporting in SQL
Hands-on interactive exercise
Have a go at this exercise by completing this sample code.
-- Convert country to lower case
SELECT
country,
____ AS country_altered
FROM countries
GROUP BY country;