其實Oracle DECODE 函數的實際操作與相關功能都類似 CASE or IF-THEN-ELSE 語句,是很容易操作的,以下的文章主要是通過介紹CASE or IF-THEN-ELSE 語句的實際操作與功能來描述Oracle DECODE 函數的實際應用於功能。
Oracle DECODE 函數:
功能類似 CASE or IF-THEN-ELSE 語句,但更容易.語法:
- DECODE(col/expression,search1,result1
- [,search2,result2,......,]
- [,default] )
- select job,sal,
- DECODE(job,'ANALYST',SAL*1.1,
- 'CLERK',SAL*1.15,
- 'MANAGER',SAL*1.20,
- SAL)
- REVISER_SALARY
- * FROM scott.emp
- JOB SAL REVISER_SALARY
- CLERK 800 920
- SALESMAN 1600 1600
- SALESMAN 1250 1250
- MANAGER 2975 3570
- SALESMAN 1250 1250
- MANAGER 2850 3420
- MANAGER 2450 2940
- ANALYST 3000 3300
- PRESIDENT 5000 5000
- SALESMAN 1500 1500
- CLERK 1100 1265
- CLERK 950 1092.5
- ANALYST 3000 3300
- CLERK 1300 1495
Oracle DECODE 函數命令:
save:把sqlplus中的命令,保存在硬盤中.例如:
SQL> save 'D:\selectEmp.txt'
已創建文件 D:\selectEmp.txt
get:把命令從硬盤中加載到sqlplus環境中. 然後 鍵入 run或r或/ 執行.例如:
- SQL> get 'D:\selectEmp.txt'
- 1* select * from scott.emp
- SQL> r
- 1* select * from scott.emp
- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
- 7369 SMITH CLERK 7902 17-12月-80 800 20
- 7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
- 7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
- 7566 JONES MANAGER 7839 02-4月 -81 2975 20
- 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30
@:把命令從硬盤中加載到sqlplus環境中 並自動執行.例如:
- SQL> @ D:\selectEmp.txt
- EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
- 7369 SMITH CLERK 7902 17-12月-80 800 20
- 7499 ALLEN SALESMAN 7698 20-2月 -81 1600 300 30
- 7521 WARD SALESMAN 7698 22-2月 -81 1250 500 30
- 7566 JONES MANAGER 7839 02-4月 -81 2975 20
- 7654 MARTIN SALESMAN 7698 28-9月 -81 1250 1400 30