Use if logic in Oracle SQL statements

Source: Internet
Author: User

L Use If-then-else logic in SQL statements LL uses two methods: CASE expression: SQL99 syntax, similar to basic, cumbersome decode functions: Oracle's own syntax, Java-like, comparative introduction

1Sql> SelectEname,job, Sal, CaseJob when 'President'  Then 1.1*Sal2   2                                when 'MANAGER'  Then 1.2*Sal3   3                                 when 'Clerk'  Then 1.3*Sal4   4                                 Else 1.4*Sal5   5                                Endsalary after rise6   6   fromEMP7   7  ;8  9 ename JOB SAL salary after riseTen ---------- --------- --------- ---------- OneSMITH Clerk800.00       1040 AALLEN salesman1600.00       2240 -WARD salesman1250.00       1750 -JONES MANAGER2975.00       3570 theMARTIN salesman1250.00       1750 -BLAKE MANAGER2850.00       3420 -CLARK MANAGER2450.00       2940 -KING President5000.00       5500 +TURNER salesman1500.00       2100 -JAMES Clerk950.00       1235 +FORD ANALYST3000.00       4200 AMILLER Clerk1400.00       1820 atjack_12342000.00       2800 -   -  -rows Selected -  -Sql> SelectEname,job, Sal,decode (Job,'President',1.1*Sal, -   2                                   'MANAGER',1.2*Sal, in   3                                   'Clerk',1.3*Sal, -   4                                           1.4*Sal) pay rise after to   5   fromEMP; +   - ename JOB SAL salary after rise the ---------- --------- --------- ---------- *SMITH Clerk800.00       1040 $ALLEN salesman1600.00       2240Panax NotoginsengWARD salesman1250.00       1750 -JONES MANAGER2975.00       3570 theMARTIN salesman1250.00       1750 +BLAKE MANAGER2850.00       3420 ACLARK MANAGER2450.00       2940 theKING President5000.00       5500 +TURNER salesman1500.00       2100 -JAMES Clerk950.00       1235 $FORD ANALYST3000.00       4200 $MILLER Clerk1400.00       1820 -jack_12342000.00       2800 -   the  -Rows selected

Use if logic in Oracle SQL statements

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.