UPPER और LOWER
In this page:
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
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
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
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
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
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;
- एक बड़ी table पर
UPPER(col) = Xcompare करना और index इस्तेमाल होने से रोकना। - यह भूल जाना कि
UPPERऔरLOWERstored data नहीं बदलते, सिर्फ result बदलते हैं। - यह उम्मीद करना कि वे हर character set में special characters को same तरह handle करेंगे।
Chapter Quiz — Complete all 7 topics to unlock
0/7 topics done
Complete these topics first: