Loading Page Content...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Preparing courses, live labs, and learning resources.सामग्री लोड हो रही है, कृपया प्रतीक्षा करें...
Raw text stored in database tables is rarely in the exact display format required by end-user interfaces. Names need capitalizing, full names need stitching together from first and last names, email domains need extracting, and messy user input containing trailing spaces needs sanitizing. SQL provides a rich library of built-in Scalar String Functions.
CONCAT() and CONCAT_WS()In standard SQL (and unlike Python or JavaScript), you cannot use the plus operator (+) to concatenate strings (in MySQL, 'A' + 'B' converts both to 0 and yields 0!). You must use concatenation functions:
CONCAT(str1, str2, ...)Joins strings together sequentially. Crucial Rule: If any argument is NULL, CONCAT() returns NULL!
CONCAT_WS(separator, str1, str2, ...) (Concatenate With Separator)The first argument is the delimiter. Unlike CONCAT(), CONCAT_WS skips NULL values automatically!
UPPER() and LOWER()LENGTH() vs CHAR_LENGTH()Understanding the difference between byte length and character length is critical when dealing with multilingual Unicode text:
LENGTH(str): Returns length in bytes.CHAR_LENGTH(str): Returns length in characters. Always use CHAR_LENGTH when measuring text length for user validation!SUBSTRING() / SUBSTR()Extracts a slice of text starting at a specific position. Note: SQL indexes strings starting at 1, NOT 0!
TRIM(), LTRIM(), and RTRIM()Removes unwanted leading and trailing whitespace characters:
REPLACE()Replaces all occurrences of a search string with a replacement string:
SUBSTRING() function), what is the index position of the first character?CONCAT('Hello', NULL, 'World') return in MySQL?SELECT SUBSTRING('DATABASE', 5, 4);?Continue learning with hands-on practice, examples, and exercises in the upcoming topic.
| Previous Lesson | Next Lesson |
|---|---|
| Pagination with LIMIT and OFFSET | Numeric & Math Functions |
Test your understanding of this lesson with 5 questions. Each question has one correct answer.