স্ট্রিং-এর শেষ ৪ অক্ষর মুছতে SUBSTRING() এবং UPDATE কমান্ড ব্যবহার করুন।
টেবিল তৈরি করা
mysql> create table DemoTable ( StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, StudentSubject varchar(100) ); Query OK, 0 rows affected (0.57 sec)
রেকর্ড ইনসার্ট করা
mysql> insert into DemoTable(StudentSubject) values('Introduction to Java'); Query OK, 1 row affected (0.14 sec)
mysql> insert into DemoTable(StudentSubject) values('Introduction to C'); Query OK, 1 row affected (0.13 sec)
mysql> insert into DemoTable(StudentSubject) values('Introduction to C++'); Query OK, 1 row affected (0.11 sec)
mysql> insert into DemoTable(StudentSubject) values('Spring And Hibernate'); Query OK, 1 row affected (0.13 sec)
রেকর্ড প্রদর্শন
mysql> select * from DemoTable;
আউটপুট:
+-----------+----------------------+ | StudentId | StudentSubject | +-----------+----------------------+ | 1 | Introduction to Java | | 2 | Introduction to C | | 3 | Introduction to C++ | | 4 | Spring And Hibernate | +-----------+----------------------+ 4 rows in set (0.00 sec)
শেষ ৪ অক্ষর ডিলিট করা
mysql> update DemoTable set StudentSubject=SUBSTRING(StudentSubject, 1, LENGTH(StudentSubject)-4); Query OK, 4 rows affected (0.16 sec) Rows matched: 4 Changed: 4 Warnings: 0
পরিবর্তন যাচাই করা
mysql> select * from DemoTable;
আউটপুট:
+-----------+------------------+ | StudentId | StudentSubject | +-----------+------------------+ | 1 | Introduction to | | 2 | Introduction | | 3 | Introduction to | | 4 | Spring And Hiber | +-----------+------------------+ 4 rows in set (0.00 sec)
ব্যাখ্যা: SUBSTRING(str, 1, LENGTH(str)-4) স্ট্রিং-এর প্রথম ক্যারেক্টার থেকে (লেনথ-৪) পর্যন্ত ক্যারেক্টার রিটার্ন করে, অর্থাৎ শেষ ৪টি বাদ দেয়। WHERE ক্লজ না থাকায় সব রো আপডেট হয়েছে।