Extracts a portion of characters from a string starting at a specified position. An alias for SUBSTRING, highly useful for data extraction and parsing.
STRINGDiperbarui: 13 Jun 2026SUBSTR(value, position [, length])The string to extract from
The starting position (1-indexed). Negative values count from the end of the string
The number of characters to extract. If omitted, extracts through the end of the string
1 SELECT SUBSTR('Hello World', 1, 5) as result;
Extracts the first 5 characters.
1 SELECT SUBSTR('Hello World', 7) as result;
Extracts from position 7 through the end of the string.
1 SELECT SUBSTR('Hello World', -5) as result;
Extracts the last 5 characters.
1 SELECT 2 product_id, 3 SUBSTR(product_id, 1, 3) as category_code, 4 SUBSTR(product_id, 4, 4) as product_code, 5 SUBSTR(product_id, -2) as variant_code 6 FROM `project.dataset.products` 7 LIMIT 3;
Parses components from a product_id in the format: CAT0001XX
| product_id | category_code | product_code | variant_code |
|---|---|---|---|
| ELC0001AB | ELC | 0001 | AB |
| FSN0025XL | FSN | 0025 | XL |
Sudah paham SUBSTR? Latih langsung di browser
Latihan interaktif, langsung di browser.
RIGHT