RPAD
是一個 SQL 函數,用于在字符串的右側填充指定的字符,直到達到指定的長度
RPAD
函數補全員工編號:SELECT employee_id, RPAD(employee_id, 6, '0') AS padded_employee_id
FROM employees;
RPAD
函數格式化電話號碼:SELECT phone_number, RPAD(REPLACE(phone_number, '-', ''), 10, 'X') AS formatted_phone_number
FROM customers;
RPAD
函數和其他字符串函數生成報告標題:SELECT CONCAT(RPAD('Sales Report', 20, ' '), '|', RPAD('Product', 15, ' '), '|', 'Amount') AS report_title
FROM sales
LIMIT 1;
RPAD
函數和其他聚合函數計算每個部門的總銷售額:SELECT department_id, SUM(sales_amount) AS total_sales, RPAD('', 20, '=') AS separator
FROM sales
GROUP BY department_id;
這些示例展示了如何在不同場景中結合其他函數使用 RPAD
。你可以根據實際需求調整查詢語句。