Sử dụng SUBSTR(chuoi, 2) hoặc SUBSTRING(chuoi, 2) để lấy chuỗi con từ ký tự thứ 2 đến hết (bỏ ký tự đầu).
Ví dụ
Tạo bảng FirstName:
mysql> create table DemoTable ( FirstName varchar(20) ); Query OK, 0 rows affected (0.63 sec)
Dữ liệu: Larry, Carol, Robert, David
Bỏ ký tự đầu
mysql> select substr(FirstName,2) from DemoTable;
+---------------------+ | substr(FirstName,2) | +---------------------+ | arry | | arol | | obert | | avid | +---------------------+
Cú pháp SUBSTR/SUBSTRING:
SUBSTR(str, pos)- từ vị trí pos đến hếtSUBSTR(str, pos, len)- từ pos lấy len ký tự- Vị trí bắt đầu từ 1. Vị trí âm: tính từ cuối (-1 = ký tự cuối)
Ví dụ vị trí âm: SUBSTR('Hello', -3) → 'llo' (3 ký tự cuối).