Q.Let us use Customer relation shown in Table 9.10 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 →This is Example 9.20 of the textbook — it uses the real CUSTOMER table (Table 9.10) of the CARSHOWROOM database and demonstrates LOWER/UPPER, LENGTH/LEFT/INSTR, MID, TRIM(... FROM ...), and LIKE.
The real CUSTOMER table (Table 9.10)
| CustId | CustName | CustAdd | Phone | |
|---|---|---|---|---|
| C0001 | Amit Saha | L-10, Pitampura | 4564587852 | amitsaha2@gmail.com |
| C0002 | Rehnuma | J-12, SAKET | 5527688761 | rehnuma@hotmail.com |
| C0003 | Charvi Nayyar | 10/9, FF, Rohini | 6811635425 | charvi123@yahoo.com |
| C0004 | Gurpreet | A-10/2, SF, Mayur Vihar | 3511056125 | gur_singh@yahoo.com |
There is no separate City column — a customer's locality (like "Rohini") is embedded inside the single CustAdd string, so any filter on locality must use LIKE, not =.
(a) Display customer name in lower case and customer email in upper case from table CUSTOMER.
SELECT LOWER(CustName), UPPER(Email) FROM CUSTOMER;
Output
| LOWER(CustName) | UPPER(Email) |
|---|---|
| amit saha | AMITSAHA2@GMAIL.COM |
| rehnuma | REHNUMA@HOTMAIL.COM |
| charvi nayyar | CHARVI123@YAHOO.COM |
| gurpreet | GUR_SINGH@YAHOO.COM |
(b) Display the length of the email and part of the email from the email id before the character '@'. Note — Do not print '@'.
SELECT LENGTH(Email), LEFT(Email, INSTR(Email, "@")-1) FROM CUSTOMER;
INSTR(Email, "@") finds the 1-based position of @; subtracting 1 gives how many characters come before it, and LEFT(Email, n) takes exactly that many characters from the start.
Output — every email in this table happens to be 19 characters long:
| LENGTH(Email) | LEFT(Email, INSTR(Email,"@")-1) |
|---|---|
| 19 | amitsaha2 |
| 19 | rehnuma |
| 19 | charvi123 |
| 19 | gur_singh |
(c) Let us assume that four-digit area code is reflected in the mobile number starting from position number 3. For example, 1851 is the area code of mobile number 9818511338. Now, write the SQL query to display the area code of the customer living in Rohini.
SELECT MID(Phone, 3, 4)
FROM CUSTOMER
WHERE CustAdd LIKE '%Rohini%';
Only C0003 (Charvi Nayyar, address "10/9, FF, Rohini") matches. MID(Phone, 3, 4) on her number 6811635425 takes 4 characters starting at position 3: 1163.
Output
| MID(Phone,3,4) |
|---|
| 1163 |
9818511338 in the question is only an illustrative example of the extraction method (its area code is 1851) — it is not any real customer's number in Table 9.10. The query itself runs against the real Phone column of whichever row matches CustAdd LIKE '%Rohini%'.
--- …
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.