0

我对 SQL 比较陌生。我正在尝试编写一个查询,其中“date_requested”列将四舍五入到最近的一天,并将结果放入一个新列中。我知道代码不是最漂亮的,但它可以在另一个报告中完成工作。我添加了 ROUND 函数的代码,但我不断收到错误消息:“ORA-0933:SQL 命令未正确结束”。

SELECT "RIT"."RIT_REQUEST_V".*   
FROM "RIT"."RIT_REQUEST_V"  
ROUND(to_date(''DATE_REQUESTED'') "DAY_REQUESTED"
WHERE (("FORM_ID" = 2011) 
OR ("FORM_ID" = 2014) 
OR ("FORM_ID" = 5007) 
OR ("FORM_ID" = 5036) 
OR ("FORM_ID" = 5039) 
OR ("FORM_ID" = 7007) 
OR ("FORM_ID" = 10000) 
OR ("FORM_ID" = 10001) 
OR ("FORM_ID" = 10005) 
OR ("FORM_ID" = 10007) 
OR ("FORM_ID" = 10011) 
OR ("FORM_ID" = 10020) 
OR ("FORM_ID" = 10024) 
OR ("FORM_ID" = 10025) 
OR ("FORM_ID" = 10029) 
OR ("FORM_ID" = 10032) 
OR ("FORM_ID" = 10033) 
OR ("FORM_ID" = 10034) 
OR ("FORM_ID" = 10035) 
OR ("FORM_ID" = 10036) 
OR ("FORM_ID" = 10037) 
OR ("FORM_ID" = 11011) 
OR ("FORM_ID" = 11013) 
OR ("FORM_ID" = 11999) 
OR ("FORM_ID" = 36001))
AND (("STATUS" LIKE 'OPEN%')
OR ("STATUS" LIKE 'Open%'))
4

1 回答 1

1

两个小错误:

  1. 你把计算的列DAY_REQUESTED放在后面FROM
  2. 末尾缺少一个括号ROUND

最后你可以使用IN而不是 many OR's 。这使代码更易于维护:

SELECT "RIT"."RIT_REQUEST_V".*,
        ROUND(to_date(E_DATREQUESTED)) "DAY_REQUESTED"
  FROM "RIT"."RIT_REQUEST_V"
 WHERE FORM_ID IN (2011,2014,5007,5036,5039,7007,10000,
                   10001,10005,10007,10011,10020,10024,
                   10025,10029,10032,10033,10034,10035,
                   10036,10037,11011,11013,11999,36001)   
   AND (("STATUS" LIKE 'OPEN%') OR
        ("STATUS" LIKE 'Open%'));

ps修正了一个小错字FORM_ID IN

于 2013-04-11T18:53:11.837 回答