是否可以在 BIRT 查询中使模式名称动态化。
我试过这个:
SELECT CURRENT DATE AS DATE,
(CASE WHEN DAYOFWEEK(CURRENT DATE) = 1 THEN 'SUNDAY'
WHEN DAYOFWEEK(CURRENT DATE) = 2 THEN 'MONDAY'
WHEN DAYOFWEEK(CURRENT DATE) = 3 THEN 'TUESDAY'
WHEN DAYOFWEEK(CURRENT DATE) = 4 THEN 'WEDNESDAY'
WHEN DAYOFWEEK(CURRENT DATE) = 5 THEN 'THURSDAY'
WHEN DAYOFWEEK(CURRENT DATE) = 6 THEN 'FRIDAY'
WHEN DAYOFWEEK(CURRENT DATE) = 7 THEN 'SATURDAY'
END) AS DAYOFWEEK
FROM **?**.COBOL_CALENDAR
WHERE SERVICE_DATE = CURRENT DATE"
这会产生以下错误:以下项目有错误:
ReportDesign (id = 1):
+ Cannot get the result set metadata.
SQL statement does not return a ResultSet object.
SQL error #1: [IBM][CLI Driver][DB2] SQL0104N An unexpected token "?" was found following "". Expected tokens may include: "( TABLE FINAL <IDENTIFIER> XMLTABLE". SQLSTATE=42601
但是 ? 似乎只适用于 where 子句。
我需要将模式作为参数传递并动态使用,因为它会根据 dev/cat/prod 更改
是否没有某种方法可以在 birt xml 外部生成 sql 并以某种方式注入它?
我对该主题进行了更多搜索并找到了此解决方案
<method name="beforeOpen"><![CDATA[this.queryText = "SELECT CURRENT DATE AS DATE, "+
"(CASE WHEN DAYOFWEEK(CURRENT DATE) = 1 THEN 'SUNDAY'"+
" WHEN DAYOFWEEK(CURRENT DATE) = 2 THEN 'MONDAY'"+
" WHEN DAYOFWEEK(CURRENT DATE) = 3 THEN 'TUESDAY'"+
" WHEN DAYOFWEEK(CURRENT DATE) = 4 THEN 'WEDNESDAY'"+
" WHEN DAYOFWEEK(CURRENT DATE) = 5 THEN 'THURSDAY'"+
" WHEN DAYOFWEEK(CURRENT DATE) = 6 THEN 'FRIDAY'"+
" WHEN DAYOFWEEK(CURRENT DATE) = 7 THEN 'SATURDAY'"+
" END) AS DAYOFWEEK"+
"FROM "+params["SCHEMA"]+".COBOL_CALENDAR"+
" WHERE SERVICE_DATE = CURRENT DATE";]]></method>
但是,无论有多少关于此问题的示例以这种方式注入 sql 只会产生以下错误。
ReportDesign (id = 1):
+ Cannot get the result set metadata.
SQL statement does not return a ResultSet object.
SQL error #1: [IBM][CLI Driver][DB2] SQL0104N An unexpected token "SCHEMANAME" was found following "". Expected tokens may include: ", FROM INTO". SQLSTATE=42601
我什至尝试reportContext.getParameterValue("SCHEMANAME")
了同样结果的路线。