CBSE Class 12 Informatics Practices Question 52 of 81

MySQL Functions — Question 3

Back to all questions
3
Question

Question 2(ii)

Explain the TRIM() SQL function using suitable examples.

Answer

The TRIM() function removes leading and trailing spaces from a given string. It performs the combined functions of LTRIM() and RTRIM(). The syntax is:

TRIM([{BOTH|LEADING|TRAILING} [remstr] FROM] str) or TRM([remstr FROM] str).

It returns the string str with all remstr prefixes or suffixes removed. If none of the specifiers (BOTH, LEADING, or TRAILING) are given, BOTH is assumed. remstr is optional, and if not specified, spaces are removed. For example,

SELECT TRIM('   Bar One  ');
Output
+----------------------+
| TRIM('   Bar One  ') |
+----------------------+
| Bar One              |
+----------------------+