Q.Using the CUSTOMER relation (Table 1.2) to understand the working of string functions:
You're viewing a preview — the full solution, concept, methods & PYQ mapping are locked.
Start your 14-day free trial to unlock the full solution →Five string-function queries on the real CUSTOMER table (Table 1.2): case conversion (LOWER/UPPER), length + substring extraction (LENGTH/LEFT/INSTR), a fixed-position substring (MID), removing a suffix (TRIM ... FROM), and a pattern filter (LIKE).
This is a code/query task. Every part works on the same four-row CUSTOMER table:
| CustId | CustName | CustAdd | Phone | |
|---|---|---|---|---|
| C0001 | AmitSaha | L-10, Pitampura | 4564587852 | amitsaha2@gmail.com |
| C0002 | Rehnuma | J-12, SAKET | 5527688761 | rehnuma@hotmail.com |
| C0003 | CharviNayyar | 10/9, FF, Rohini | 6811635425 | charvi123@yahoo.com |
| C0004 | Gurpreet | A-10/2, SF, MayurVihar | 3511056125 | gur_singh@yahoo.com |
(a) Case conversion. LOWER()/LCASE() and UPPER()/UCASE() change every character's case:
SELECT LOWER(CustName), UPPER(Email) FROM CUSTOMER;
(b) Length and the part before '@'. INSTR(Email, "@") returns the 1-based position of @ in each address (position 10 for amitsaha2@gmail.com). LEFT(Email, that position - 1) then returns everything up to, but excluding, the @ itself — the -1 is what keeps @ out of the result.
SELECT LENGTH(Email), LEFT(Email, INSTR(Email, "@")-1) FROM CUSTOMER;
Forgetting the -1 in LEFT(Email, INSTR(Email,"@")) would include the @ itself in the output — the question explicitly says "do not print '@'".
(c) A fixed-position substring. MID(string, pos, n) (also SUBSTRING/SUBSTR) pulls n characters starting at position pos. The area code sits at position 3, 4 characters long:
SELECT MID(Phone, 3, 4) FROM CUSTOMER WHERE CustAdd LIKE '%Rohini%';
Only CharviNayyar's address contains "Rohini"; her Phone is 6811635425, and MID(Phone, 3, 4) reads characters 3-6: 1163.
(d) Removing a suffix. TRIM() isn't only for whitespace — TRIM(remstr FROM string) strips a specific substring:
SELECT TRIM(".com" FROM Email) FROM CUSTOMER;
``` …
Unlock everything free for 14 days
- Full step-by-step solutions
- Concept-first explanations
- Methods, shortcuts & mistakes
- PYQ mapping + timed mock tests
Full access for 14 days. No credit card required.