String Functions — Concept Check
Questions on String Functions. CONCAT, SUBSTRING, LENGTH, REPLACE, UPPER/LOWER, TRIM, REGEXP_REPLACE, and FORMAT are core string functions; MySQL is case-insensitive for string comparison by default (COLLATION-dependent).
Questions in this quiz
8 questions on String Functions — Concept Check. Work through them here, then start the quiz to answer them and see your score.
1.A developer needs to combine first and last names from a database but notices some entries have NULL values. Which function should they use to avoid NULL results in the output?
- AFORMAT
- BCONCAT
- CSUBSTRING
- DCONCAT_WS
2.You want to extract the word 'World' from the string 'Hello World' using a function. Which function and parameters would you use?
- AMID('Hello World', 1, 5)
- BLEFT('Hello World', 5)
- CRIGHT('Hello World', 5)
- DSUBSTRING('Hello World', 7, 5)
3.A report requires numbers to be displayed with commas as thousand separators. Which function will achieve this?
- AREPLACE
- BCONCAT
- CFORMAT
- DREGEXP_REPLACE
4.A developer is trying to replace all occurrences of 'World' with 'MySQL' in a string. They mistakenly use REGEXP_REPLACE. Why might this be incorrect?
- AREGEXP_REPLACE is for regex patterns, not literal strings
- BREGEXP_REPLACE doesn't exist in MySQL
- CREPLACE is faster than REGEXP_REPLACE
- DREGEXP_REPLACE only works on numbers
5.How can you ensure a case-sensitive search in MySQL when the default collation is case-insensitive?
- AUse TRIM function
- BChange collation to utf8mb4_unicode_ci
- CUse BINARY keyword
- DUse LOWER function
6.A developer uses LENGTH to determine the visible length of a UTF-8 string. What's a potential issue with this approach?
- ALENGTH returns NULL for UTF-8
- BLENGTH is deprecated
- CLENGTH only works on ASCII
- DLENGTH counts bytes, not characters
7.You need to find the position of 'World' in 'Hello World'. Which function and result are correct?
- AINSTR('World', 'Hello World') returns 7
- BLOCATE('World', 'Hello World') returns 0
- CINSTR('Hello World', 'World') returns 0
- DLOCATE('World', 'Hello World') returns 7
8.A developer uses CONCAT to join strings but gets NULL as a result. What might be the reason?
- ACONCAT is case-sensitive
- BOne of the arguments is NULL
- CCONCAT cannot join more than two strings
- DCONCAT requires numeric inputs