簡體   English   中英

Oracle SQL查詢缺少關鍵字錯誤

[英]Oracle Sql query missing keyword error

我正在嘗試這個查詢

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;

但顯示缺少關鍵字錯誤

我在“ commission_pct> 0”點收到此錯誤。

請幫我

別名在單詞end之后出現。

select case when this then that
else somethingelse end aliasName

你有這個:

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

就語法而言,這應該可以:

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;

但是,這沒有多大意義-前兩個CASE條件幾乎相同-請注意,

  • 1st: when commision_pct <= 0.15
  • 第二名: when commision_pct < 0.15

我說你必須改變它。

[編輯:關鍵字不遺漏]

我創建了一個虛擬的 EMPLOYEES表,以使查詢不會失敗。 然后我運行它-如您所見,一切都很好。 我建議您執行相同的操作-在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>

這是您的查詢:

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