LEFT() फंक्शन का उपयोग करना
MySQL में किसी कॉलम के मान के पहले N कैरेक्टर निकालने के लिए LEFT() फंक्शन का उपयोग करें।
सिंटैक्स
SELECT LEFT(yourColumnName, 200) AS anyAliasName FROM yourTableName;
उदाहरण
1. टेबल बनाना
mysql> CREATE TABLE DemoTable (Paragraph LONGTEXT); Query OK, 0 rows affected (0.71 sec)
2. लंबा टेक्स्ट डालना
mysql> INSERT INTO DemoTable VALUES(
'Introduction to Java,Introduction to C,Introduction to C++,
Introduction to Spring,Introduction to Hibernate,Introduction to Python,
Introduction to MySQL,Introduction to MongoDB,Introduction to SQL Server,
Introduction to ASP.net,Introduction to JSF'
);
Query OK, 1 row affected (0.13 sec)
3. पूरा मान देखना
mysql> SELECT * FROM DemoTable;
+--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Paragraph | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Introduction to Java,Introduction to C,Introduction to C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to MySQL,Introduction to MongoDB,Introduction to SQL Server,Introduction to ASP.net,Introduction to JSF | +--------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
4. केवल पहले 200 कैरेक्टर निकालना
mysql> SELECT LEFT(Paragraph, 200) AS `200Characters` FROM DemoTable;
+----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | 200Characters | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ | Introduction to Java,Introduction to C,Introduction to C++,Introduction to Spring,Introduction to Hibernate,Introduction to Python,Introduction to MySQL,Introduction to MongoDB,Introduction to SQL Ser | +----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------+ 1 row in set (0.00 sec)
संबंधित फंक्शन
| फंक्शन | विवरण |
|---|---|
| LEFT(str, len) | बाएं से len कैरेक्टर लौटाता है |
| RIGHT(str, len) | दाएं से len कैरेक्टर लौटाता है |
| SUBSTRING(str, pos, len) | स्थिति pos से len कैरेक्टर लौटाता है |
| SUBSTR(str, pos, len) | SUBSTRING का पर्यायवाची |
नोट
LEFT() मल्टी-बाइट कैरेक्टर (जैसे UTF-8 में हिंदी/चीनी) के लिए कैरेक्टर गिनता है, बाइट्स नहीं।