在SAP HANA中探索分析视图的过程

时间:2013-10-22 07:23:10

标签: stored-procedures sap dimension measure hana

我正在创建一个可以在给定一维,一个度量和过滤器(where子句)的情况下探索分析视图的过程

drop procedure dynamicExploration;

create procedure dynamicExploration(in currentMeasure double, in filter_string 
varchar(100), out dataSubset dataExplorationOutputType)
language sqlscript as

begin
      dataSplitby = select CITY as ID, SUM(:currentMeasure) as SUM_MEASURE from
     _SYS_BIC."package/analyticView" Group by CITY;

  --dataSubset = APPLY_FILTER(:dataSplitby, :filter_string);
  dataSubset = select * from :dataSplitBy;
end;

其中dataSubset是一种定义如下的数据类型:

drop type dataExplorationOutputType;
create type dataExplorationOutputType as table("ID" varchar(100), "SUM_MEASURE" double);

但是我收到了这个错误,请你检查一下是什么错误;

Could not execute 'create procedure dynamicExploration(in currentMeasure double, in    
filter_string varchar(100), out ...' in 166 ms 8 µs .
SAP DBTech JDBC: [266] (at 200): inconsistent datatype: only numeric type is available    
for aggregation function: line 4 col 36 (at pos 200)

我还尝试将currentMeasure定义为varchar但仍然得到相同的错误。

我最终想要实现的是创建一个存储过程,可以帮助另一个过程根据用户定义的一组给定参数选择数据子集:维度,度量和过滤器。

drop procedure dynamicExploration;

create procedure dynamicExploration(in currentDimension varchar(100), in currentMeasure   double, in filter_string 
 varchar(100), out dataSubset dataExplorationOutputType)
 language sqlscript as

 begin
  dataSplitby = select :currentDimension as ID, SUM(:currentMeasure) as SUM_MEASURE from
  _SYS_BIC."package/analyticView" Group by :currentDimension;

  dataSubset = APPLY_FILTER(:dataSplitby, :filter_string);
 --dataSubset = select * from :dataSplitBy;
 end;

我已经创建了一个基于动态SQL进行此类动态探索的过程,这是一个不推荐的功能。我正在寻找的是一种更好的解决方案/想法,可以对分析视图(数据立方体)进行这种动态探索。

感谢

1 个答案:

答案 0 :(得分:2)

您必须构造一个动态SQL并使用EXECUTE IMMEDIATE命令执行它。我知道不推荐,但你的用例需要它。确保保护自己免受SQL注入,例如通过检查传递到包装器过程中的维度名称对照“允许”维度列表