【问题标题】:ORA-00936: missing expression?ORA-00936: 缺少表达式?
【发布时间】:2017-12-16 16:12:36
【问题描述】:

试图弄清楚为什么这行不通

【问题讨论】:

  • 重写为case语句

标签: sql oracle decode ora-00936


【解决方案1】:

由于在解码语句中使用 < > = 而导致的问题,请改用它:

SELECT a.account_id "Account ID",
   a.first_name ||' '|| a.last_name "Name",
   b.date_and_time_created "Date Created",
   c.date_and_time_ordered "Date Ordered",
   c.date_and_time_ordered - b.date_and_time_created "Days Ordered After Created",
   (case when ( c.date_and_time_ordered - b.date_and_time_created  <  5 ) then 'No Reminder Needed'
         when ( c.date_and_time_ordered - b.date_and_time_created  >= 5 ) then 'Reminder Needed'
         else ' '
     end ) "Reminder"
FROM shopper a 
   JOIN shopping_cart b ON a.account_id = b.shopper_account_id
   JOIN orders c ON a.account_id = c.shopper_account_id

【讨论】:

  • 谢谢,必须修复 CASE 中括号的一个小错误(第二个 WHEN 子句的行上的额外右括号),但除此之外,谢谢!
  • 不客气,谢谢我删除了多余的括号,我忘了删除。
【解决方案2】:

或者,如果您坚持使用 DECODE(不过,我不知道您为什么要这样做,因为 CASE 在这里更合适),您可以使用 SIGN 函数,例如

SELECT DECODE (
          SIGN ( (c.date_and_time_ordered - b.date_and_time_created) - 5),
          -1, 'less than 5',
          'greater than or equal to 5')
          result
  FROM ...

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2012-05-18
    • 2017-08-31
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多