Tips for Oracle DECODE function operations

Source: Internet
Author: User

In fact, the actual operations and related functions of the Oracle DECODE function are similar to the CASE or IF-THEN-ELSE statement, which is easy to operate, the following articles mainly describe the actual application of the Oracle DECODE function by introducing the actual operations and functions of the CASE or IF-THEN-ELSE statement.

Oracle DECODE function:

The function is similar to the CASE or IF-THEN-ELSE statement, but it is easier. Syntax:

 
 
  1. DECODE(col/expression,search1,result1  
  2. [,search2,result2,......,]  
  3. [,default] )  
  4. select job,sal,  
  5. DECODE(job,'ANALYST',SAL*1.1,  
  6. 'CLERK',SAL*1.15,  
  7. 'MANAGER',SAL*1.20,  
  8. SAL)  
  9. REVISER_SALARY  
  10. * FROM scott.emp  
  11. JOB SAL REVISER_SALARY  
  12. CLERK 800 920  
  13. SALESMAN 1600 1600  
  14. SALESMAN 1250 1250  
  15. MANAGER 2975 3570  
  16. SALESMAN 1250 1250  
  17. MANAGER 2850 3420  
  18. MANAGER 2450 2940  
  19. ANALYST 3000 3300  
  20. PRESIDENT 5000 5000  
  21. SALESMAN 1500 1500  
  22. CLERK 1100 1265  
  23. CLERK 950 1092.5  
  24. ANALYST 3000 3300  
  25. CLERK 1300 1495  

Oracle decode function command:

Save: save the commands in sqlplus in the hard disk. For example:

SQL> save 'd: \ selectEmp.txt'

Created file D: \ selectEmp.txt

Get: load the command from the hard disk to the sqlplus environment. Then type run or r or/to execute. For example:

 
 
  1. SQL> get 'd: \ selectEmp.txt'
  2. 1 * select * from scott. emp
  3. SQL> r
  4. 1 * select * from scott. emp
  5. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
  6. 7369 smith clerk 7902-12-80 800 20
  7. 7499 allen salesman 7698 20-2 month-81 1600 300 30
  8. 7521 ward salesman 7698 22-2 month-81 1250 500 30
  9. 7566 jones manager 7839 2975-81 20
  10. 7654 martin salesman 7698 28-9 month-81 1250 1400 30

@: Load the command from the hard disk to the sqlplus environment and execute it automatically. For example:

 
 
  1. SQL> @ D: \ selectEmp.txt
  2. EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
  3. 7369 smith clerk 7902-12-80 800 20
  4. 7499 allen salesman 7698 20-2 month-81 1600 300 30
  5. 7521 ward salesman 7698 22-2 month-81 1250 500 30
  6. 7566 jones manager 7839 2975-81 20
  7. 7654 martin salesman 7698 28-9 month-81 1250 1400 30

The above content is an introduction to the Oracle DECODE function and Oracle DECODE function commands. I hope you will find some gains.

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.