← Back to MySQL Course | Chapter 12: String Functions | Lesson 3 of 7

UPPER और LOWER

UPPER और LOWER एक shout button और एक whisper button जैसे हैं जो letters को capitals या small letters में बदल देते हैं।
Syntax
sql
UPPER(string)
LOWER(string)

Uppercase में Convert करना

UPPER function किसी text string के सारे letters को capital letters में convert करता है। कोई भी non-letter character unchanged रहता है, इसलिए numbers और punctuation function से untouched गुज़रते हैं।

उदाहरण: Convert to Uppercase

sql
SELECT UPPER('hello world 123!') AS shouted;

Lowercase में Convert करना

LOWER function किसी text string के सारे uppercase letters को small letters में convert करता है। यह inputs standardize करने के लिए ideal है, जैसे duplicates check करने से पहले email addresses normalize करना।

उदाहरण: Convert to Lowercase

sql
CREATE TABLE users (id INT, email TEXT);
INSERT INTO users VALUES (1, '[email protected]');
SELECT LOWER(email) AS normalized_email FROM users;

Case Insensitive Comparisons

आप manually case-insensitive comparisons करने के लिए LOWER या UPPER इस्तेमाल कर सकते हैं, खासकर binary collation tables के साथ काम करते समय जहाँ MySQL अन्यथा Apple और apple को अलग strings मानेगा।

उदाहरण: Case Insensitive Comparisons

sql
CREATE TABLE fruits (id INT, name TEXT);
INSERT INTO fruits VALUES (1, 'Apple'), (2, 'apple');
SELECT * FROM fruits WHERE LOWER(name) = LOWER('APPLE');

CONCAT के साथ Combine करना

UPPER और LOWER को customized print messages और system alert values बनाने के लिए CONCAT के साथ combine किया जा सकता है, जैसे mixed-case data से एक uppercase warning label बनाना।

उदाहरण: Combining with CONCAT

sql
CREATE TABLE alerts (id INT, level TEXT, message TEXT);
INSERT INTO alerts VALUES (1, 'warning', 'disk space low');
SELECT CONCAT(UPPER(level), ': ', message) AS alert_line FROM alerts;

Output Names Format करना

आप UPPER और LOWER functions को सीधे अपनी select lists पर apply करके poorly formatted user records साफ कर सकते हैं, जैसे stored data बदले बिना names को Title Case-adjacent consistent casing में display करना।

उदाहरण: Formatting Output Names

sql
CREATE TABLE users (id INT, first_name TEXT);
INSERT INTO users VALUES (1, 'AMIT');
SELECT CONCAT(UPPER(LEFT(first_name, 1)), LOWER(SUBSTRING(first_name, 2))) AS clean_first_name FROM users;
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the view already swaps in the hi_ translation fields (or blanks these out if untranslated), so this renders correctly for both languages without a lang_code check here. #}
आम गलतियां
  1. एक बड़ी table पर UPPER(col) = X compare करना और index इस्तेमाल होने से रोकना।
  2. यह भूल जाना कि UPPER और LOWER stored data नहीं बदलते, सिर्फ result बदलते हैं।
  3. यह उम्मीद करना कि वे हर character set में special characters को same तरह handle करेंगे।
🔒

Chapter Quiz — Complete all 7 topics to unlock

0/7 topics done

Complete these topics first:

Login to run this code

C/C++/Java/PHP execution requires a free account. Your code is saved — you'll land right back in the editor after logging in.