Extracts a specified number of characters from the right (end) of a string. A more readable shorthand for extracting trailing characters.
STRINGDiperbarui: 13 Jun 2026RIGHT(value, length)The source string
The number of characters to extract from the right
1 SELECT RIGHT('BigQuery', 5) as result;
Extracts the last 5 characters.
1 SELECT 2 file_name, 3 RIGHT(file_name, 3) as extension 4 FROM `project.dataset.files` 5 LIMIT 3;
Extracts the file extension (last 3 characters).
| file_name | extension |
|---|---|
| report.pdf | |
| data.csv | csv |
| image.png | png |
1 SELECT 2 credit_card_number, 3 CONCAT('****-****-****-', RIGHT(credit_card_number, 4)) as masked_card 4 FROM `project.dataset.payments` 5 LIMIT 3;
Displays only the last 4 digits of a credit card number.
| credit_card_number | masked_card |
|---|---|
| 1234567890123456 | ****-****-****-3456 |
| 9876543210987654 | ****-****-****-7654 |
1 SELECT 2 transaction_id, 3 RIGHT(transaction_id, 6) as sequence_number 4 FROM `project.dataset.transactions` 5 WHERE RIGHT(transaction_id, 6) LIKE '0001%' 6 LIMIT 3;
Extracts the sequence number from a transaction ID.
| transaction_id | sequence_number |
|---|---|
| TRX202401000123 | 000123 |
| TRX202401000124 | 000124 |
Sudah paham RIGHT? Latih langsung di browser
Latihan interaktif, langsung di browser.