In Class XII CBSE Computer Science (Code 083) and Informatics Practices (Code 065), String (Text) Functions are a vital part of the MySQL syllabus. These are Single Row Functions that operate on a single value and return a single value.
🎨 1. Case Conversion Functions
These functions change the letter case of the input string.
Function
Purpose
Example Query
Result
LOWER() / LCASE()
Converts characters to lowercase.
SELECT LOWER('CBSE');
'cbse'
UPPER() / UCASE()
Converts characters to uppercase.
SELECT UPPER('class 12');
'CLASS 12'
📏 2. Length & Position Functions
Used to measure strings or find the exact location of specific characters inside them.
Function
Purpose
Example Query
Result
LENGTH()
Returns the number of characters in a string.
SELECT LENGTH('Informatics');
11
INSTR()
Returns the position of the first occurrence of a substring.
SELECT INSTR('Computer', 'mp');
3
✂️ 3. Substring Extraction Functions
Used to pull out a specific portion of a string. Note: In MySQL, indexing structural strings starts at 1.
Function
Purpose
Example Query
Result
LEFT()
Returns the leftmost 'n' characters.
SELECT LEFT('Science', 3);
'Sci'
RIGHT()
Returns the rightmost 'n' characters.
SELECT RIGHT('Science', 3);
'nce'
SUBSTR() / MID()
Extracts a string from a start position for 'n' characters.
SELECT SUBSTR('Database', 3, 4);
'taba'
🧹 4. Trimming Functions
Used to clean strings by removing unwanted leading or trailing whitespaces.
LTRIM(str)
Removes spaces from the Left side only.
SELECT LTRIM(' Hello');
Output: 'Hello'
RTRIM(str)
Removes spaces from the Right side only.
SELECT RTRIM('Hello ');
Output: 'Hello'
TRIM(str)
Removes spaces from Both sides cleanly.
SELECT TRIM(' Hello ');
Output: 'Hello'
💡 Important Board Exam Concepts
Keep these high-weightage problem patterns in mind before writing your paper.
A. Nested String Functions
The board often asks for evaluations of functions wrapped together. Always solve them from the inside out!
SELECT UPPER(SUBSTR('informaticspractices', 1, 11));
👉 Step 1 (Inside): SUBSTR('informaticspractices', 1, 11) ➔ 'informatics'
👉 Step 2 (Outside): UPPER('informatics') ➔ 'INFORMATICS'
B. String Indexing System
Crucial Point: Unlike Python (where indexing begins at 0), MySQL string indexing explicitly starts at 1.
SELECT SUBSTR('HELLO', 1, 1);
Output is 'H' (Not 'E')
📝 Solved Board-Style Questions
Practice these direct question variations frequently found in past years' structural papers.
Q1
Write the computed output of the following statement:
SELECT RIGHT(LTRIM(' PYTHON'), 3);
Answer Steps:
• Step 1: LTRIM() drops the leading space ➔ 'PYTHON'
• Step 2: RIGHT('PYTHON', 3) slices last 3 items ➔ 'HON'
Q2
Write a SQL command to display the first 3 characters of the column StudentName from table Students.
Answer command:
SELECT LEFT(StudentName, 3) FROM Students;
Q3
What is the structural difference between the LENGTH() and INSTR() functions?
Answer comparison:
• LENGTH() calculates and returns the absolute integer count of total characters in a given string.
• INSTR() targets and outputs the initial numerical position of the first occurrence of a matching substring within a parent string.
🎨 1. Case Conversion Functions
These functions change the letter case of the input string.
| Function | Purpose | Example Query | Result |
|---|---|---|---|
LOWER() / LCASE() |
Converts characters to lowercase. | SELECT LOWER('CBSE'); |
'cbse' |
UPPER() / UCASE() |
Converts characters to uppercase. | SELECT UPPER('class 12'); |
'CLASS 12' |
📏 2. Length & Position Functions
Used to measure strings or find the exact location of specific characters inside them.
| Function | Purpose | Example Query | Result |
|---|---|---|---|
LENGTH() |
Returns the number of characters in a string. | SELECT LENGTH('Informatics'); |
11 |
INSTR() |
Returns the position of the first occurrence of a substring. | SELECT INSTR('Computer', 'mp'); |
3 |
✂️ 3. Substring Extraction Functions
Used to pull out a specific portion of a string. Note: In MySQL, indexing structural strings starts at 1.
| Function | Purpose | Example Query | Result |
|---|---|---|---|
LEFT() |
Returns the leftmost 'n' characters. | SELECT LEFT('Science', 3); |
'Sci' |
RIGHT() |
Returns the rightmost 'n' characters. | SELECT RIGHT('Science', 3); |
'nce' |
SUBSTR() / MID() |
Extracts a string from a start position for 'n' characters. | SELECT SUBSTR('Database', 3, 4); |
'taba' |
🧹 4. Trimming Functions
Used to clean strings by removing unwanted leading or trailing whitespaces.
LTRIM(str)
Removes spaces from the Left side only.
RTRIM(str)
Removes spaces from the Right side only.
TRIM(str)
Removes spaces from Both sides cleanly.
💡 Important Board Exam Concepts
Keep these high-weightage problem patterns in mind before writing your paper.
A. Nested String Functions
The board often asks for evaluations of functions wrapped together. Always solve them from the inside out!
SUBSTR('informaticspractices', 1, 11) ➔ 'informatics'👉 Step 2 (Outside):
UPPER('informatics') ➔ 'INFORMATICS'
B. String Indexing System
Crucial Point: Unlike Python (where indexing begins at 0), MySQL string indexing explicitly starts at 1.
📝 Solved Board-Style Questions
Practice these direct question variations frequently found in past years' structural papers.
• Step 1:
LTRIM() drops the leading space ➔ 'PYTHON'• Step 2:
RIGHT('PYTHON', 3) slices last 3 items ➔ 'HON'
StudentName from table Students.
LENGTH() and INSTR() functions?
•
LENGTH() calculates and returns the absolute integer count of total characters in a given string.•
INSTR() targets and outputs the initial numerical position of the first occurrence of a matching substring within a parent string.

.png)