SQL Practice Logo

SQLPractice Online

String Functions & Operations: Concept

Module: SQL Fundamentals

String functions manipulate text data - concatenate, transform case, extract substrings, search patterns, and measure length.

**String Concatenation:**

- PostgreSQL/Oracle: || (SQL standard)

- MySQL: CONCAT() (NULL-safe)

- SQL Server: + (NOT NULL-safe)

**String Transformation:**

- UPPER(str): Convert to uppercase

- LOWER(str): Convert to lowercase

- TRIM(str): Remove leading/trailing spaces

- SUBSTRING(str, start, len): Extract substring

- LENGTH(str): Count characters

**Pattern Matching:**

- LIKE: Wildcard search (% = any chars, _ = one char)

- POSITION(substr IN str): Find substring position

- REPLACE(str, old, new): Replace text

**Performance Impact:**

- Functions on indexed columns break indexes

- Example: WHERE UPPER(email) = 'USER@EXAMPLE.COM' → full scan

- Better: Store normalized at insert, query directly

Data Engineers: Normalize gigabytes of messy CSV/JSON data daily. String functions are ETL pipeline backbone. Backend Developers: Search features, user profiles, validation all rely on string manipulation. Analysts: Report generation, customer segmentation, text parsing for dashboards.

A customer database stores names like " John Doe " (extra spaces), emails in mixed case "John.Doe@Gmail.Com", and phone numbers "555-123-4567". You need to: normalize names, search by email domain, extract area codes, and clean messy user input without breaking database performance.