简体   繁体   English

Oracle SQL查询缺少关键字错误

[英]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. 我在“ commission_pct> 0”点收到此错误。

please help me 请帮我

The alias comes after the word end . 别名在单词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 但是,这没有多大意义-前两个CASE条件几乎相同-请注意,

  • 1st: when commision_pct <= 0.15 1st: when commision_pct <= 0.15
  • 2nd: when commision_pct < 0.15 第二名: 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. 我创建了一个虚拟的 EMPLOYEES表,以使查询不会失败。 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 * Plus会话中发布CREATE TABLESELECT ,以便我们可以看到您的工作以及Oracle的响应方式。

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;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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