Mule 4:数据库:如何将 SQL 查询作为数据库 "Query Text" 中的变量传递?

Mule 4 : Database : How to pass a SQL query as a variable in database "Query Text"?

场景:我形成了一个 SQL 查询并将其存储在变量 vars.query 中 我想在 SQL 查询文本 window.

的数据库 SELECT 组件中使用此变量

为此,我在查询文本中传递了 vars.query,并在应用程序中传递了 运行。应用程序已成功部署,但在运行时失败并显示数据库:异常,预期 SQL 查询但发现 DDL

我试过以下方法:

在查询文本中添加了 :query 并在输入参数中引用了

{
    'query' : vars.hierarchyQuery
}

但我收到以下错误:


org.mule.runtime.core.internal.message.ErrorBuilder$ErrorImplementation
{
  description=Query type must be one of [SELECT, STORE_PROCEDURE_CALL] but query '?' is of type 'DDL'
  detailedDescription=Query type must be one of [SELECT, STORE_PROCEDURE_CALL] but query '?' is of type 'DDL'
  errorType=DB:BAD_SQL_SYNTAX
  cause=org.mule.extension.db.api.exception.connection.BadSqlSyntaxException
  errorMessage=-
  childErrors=[]
}

我通过这样做解决了这个问题:在查询文本中 window 将包含变量的 sql 查询引用为 #[vars.query]

可以通过在'SQL Query Text'字段中添加$(vars.query)来解决

参考:https://docs.mulesoft.com/db-connector/1.10/database-connector-select