ฟังก์ชันSUBSTRING() ของเซิร์ฟเวอร์ SQL
ตัวอย่าง
แยกอักขระ 3 ตัวออกจากสตริง โดยเริ่มต้นในตำแหน่งที่ 1:
SELECT SUBSTRING('SQL Tutorial', 1, 3) AS ExtractString;
ความหมายและการใช้งาน
ฟังก์ชัน SUBSTRING() จะแยกอักขระบางตัวออกจากสตริง
ไวยากรณ์
SUBSTRING(string, start, length)
ค่าพารามิเตอร์
Parameter | Description |
---|---|
string | Required. The string to extract from |
start | Required. The start position. The first position in string is 1 |
length | Required. The number of characters to extract. Must be a positive number |
รายละเอียดทางเทคนิค
ทำงานใน: | SQL Server (เริ่มตั้งแต่ปี 2008), ฐานข้อมูล Azure SQL, Azure SQL Data Warehouse, Parallel Data Warehouse |
---|
ตัวอย่างเพิ่มเติม
ตัวอย่าง
แยกอักขระ 5 ตัวจากคอลัมน์ "CustomerName" โดยเริ่มจากตำแหน่งที่ 1:
SELECT SUBSTRING(CustomerName, 1, 5) AS ExtractString
FROM Customers;
ตัวอย่าง
แยกอักขระ 100 ตัวออกจากสตริง โดยเริ่มต้นในตำแหน่งที่ 1:
SELECT SUBSTRING('SQL Tutorial', 1, 100) AS ExtractString;