sql / intermediate
Snippet
Standardized String Manipulation and Length Extraction
ANSI SQL provides standard scalar string functions to process text data dynamically. LOWER normalizes casing, SUBSTRING extracts fixed-position slices using 1-based indexing syntax, and CHAR_LENGTH calculates character count regardless of byte encoding.
snippet.sql
sql
1
2
3
4
5
SELECTLOWER(email) AS normalized_email,SUBSTRING(department_code FROM 1 FOR 3) AS dept_prefix,CHAR_LENGTH(username) AS name_lengthFROM user_profiles;
Breakdown
1
SELECT
Begins the column projection list.
2
LOWER(email) AS normalized_email,
Converts all characters in the email field to lowercase.
3
SUBSTRING(department_code FROM 1 FOR 3) AS dept_prefix,
Extracts 3 characters starting from position 1 using standard ANSI SQL syntax.
4
CHAR_LENGTH(username) AS name_length
Returns the exact number of characters in the username string.
5
FROM user_profiles;
Identifies user_profiles as the target database table.