SELECT TO_NUMBER(TO_CHAR(sysdate, 'YYYY')) AS year FROM dual;
該示例將當前日期轉換為年份,并將其轉換為數字類型。
SELECT TO_NUMBER(NVL(salary, 0)) AS salary FROM employees;
該示例將員工表中的薪水字段轉換為數字類型,并將空值替換為0。
SELECT CASE WHEN TO_NUMBER(age) < 18 THEN 'Minor' ELSE 'Adult' END AS age_group FROM members;
該示例根據年齡字段的值將會員分為未成年和成年兩組。
SELECT DECODE(TO_NUMBER(status), 1, 'Active', 0, 'Inactive') AS status FROM customers;
該示例根據客戶狀態字段的值將客戶分為活躍和不活躍兩組。