简体   繁体   中英

Oracle Sql query missing keyword error

I am trying this query

select 
   employee_id
  ,first_name
  ,last_name
  , case
      salary when(( commission_pct > 0) AND (commission_pct <= 0.15))  
      then salary*20/100 
      when commission_pct > 0.15
      then salary*25/100 
      else 0
    end INCENTIVE_AMT
 from employees
 order by employee_id;

but it shows missing keyword error

I am getting this error at "commission_pct > 0" point.

please help me

The alias comes after the word end .

select case when this then that
else somethingelse end aliasName

You have this:

select case when this then that aliasName
else something else aliasName end 

This should be OK, as far as syntax is concerned:

select employee_id,
  first_name,
  last_name,
  case when commision_pct > 0 and commision_pct <= 0.15 then salary * 20 / 100
       when commision_pct < 0.15                        then salary * 25 / 100
       else 0
  end incentive_amt
from employees
order by employee_id;

However, doesn't make much sense - the first two CASE conditions are almost the same - mind you, you're looking at

  • 1st: when commision_pct <= 0.15
  • 2nd: when commision_pct < 0.15

I'd say that you have to change that.

[EDIT: keyword ain't missing]

I created a dummy EMPLOYEES table so that the query wouldn't fail. Then I ran it - as you can see, everything's fine. I suggest you do the same - post CREATE TABLE and SELECT executed in your SQL*Plus session so that we could see what you did and how Oracle responded.

SQL> create table employees
  2   (employee_id   number,
  3    first_name    varchar2(20),
  4    last_name     varchar2(20),
  5    commision_pct number,
  6    salary        number
  7    );

Table created.

SQL> select employee_id,
  2    first_name,
  3    last_name,
  4    case when commision_pct > 0 and commision_pct <= 0.15 then salary * 20 / 100
  5         when commision_pct < 0.15                        then salary * 25 / 100
  6         else 0
  7    end incentive_amt
  8  from employees
  9  order by employee_id;

no rows selected

SQL>

here is your query:

select 
   employee_id,
   first_name,
   last_name, 
      case 
        when COMMISSION_PCT > 0 AND COMMISSION_PCT <= 0.15
          then salary*20/100 
        when commission_pct < 0.15
          then salary*25/100 
        else 0
      end INCENTIVE_AMT
 from employees
 order by employee_id;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM