0

我正在使用 MuleSoft (3.9) OData (2.0) RAML 并将查询传递给 Oracle 数据库。在 url 中添加日期过滤器 &$filter=START_DATE le datetime'2016-01-01T11:00:00'会引发数据库错误:

SQL 命令未正确结束。

如何将日期过滤器添加到 OData RAML?

数据库查询生成为select....where START_DATE <= datetime'2016-01-01T11:00:00'. 我们是否需要显式转换 using to_date

4

1 回答 1

0

使用以下变量将 OData 过滤器解析为 SQL 过滤器

%var odataFilterToSQLFilter = (odataFilter) -> 

    (( odataFilter replace "eq null" with "is null" 
     replace "ne null" with "is not null" 
     replace " eq " with " = " 
     replace " ne " with " != " 
     replace " gt " with " > " 
     replace " lt " with " < " 
     replace " ge " with " >= " 
     replace " le " with " <= " 
     replace " and " with " AND " 
     replace " or " with " OR " ) splitBy " " map  (
         ("TO_DATE('" ++ (($ replace "datetime'" with "" ) replace "T" with " ") ++ ",'yyyy-MM-dd HH24:MI:SS')") when $ as :string contains "datetime" otherwise $
     )) joinBy " "

%var toSQLWhere = (odataFilter) -> (" WHERE " ++ odataFilterToSQLFilter(odataFilter)) unless odataFilter == null otherwise ""

---
"SELECT " ++ generateSqlFields(filters.select) ++ " FROM $remoteEntityName"
 ++ ( 
    (toSQLWhere(filters.filter))
于 2019-02-09T01:40:33.017 回答