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;
该示例根据客户状态字段的值将客户分为活跃和不活跃两组。