FrameWork建模时构建查询主题的三种方法的比较

浏览: 2551

场景:在FM建模的时候,我们往往会创建查询主题-New Query Subject,下面我们就从如何构建查询主题,构建查询主题有哪些不同的方法,以及不同方法之间有哪些区别

展开论述。

首先我们可以看一下在FM中New Query Subject的时候有三种不同的方法供我们选择:


方法1:利用显存模型构建查询主题

此方法比较简单,选择新建查询主题向导之后,选择模型-确定,直接从左侧现存对象中拖拉过来就可以了

 

方法2:利用SQL-数据源构建查询主题

此方法较为简单,但是需要注意一些地方,选择新建查询主题向导之后,选择数据源(表格和列)-确定

会出现让我们选择确定

默认情况下上面的√是勾上的,我们选择去掉,避免一系列的选择,直接进入写SQL界面,接下来尽情发挥你的SQL功底吧

 

方法3:利用存储过程构建查询主题

此方法较为复杂,需要注意几个地方,选择新建查询主题向导之后,选择存储过程-确定

会出现让我们选择确定存储过程

选择GETORDER完成,测试报错如下,无法返回结果集

基于上面的错误去官网查看解决办法

URL: https://www-304.ibm.com/support/docview.wss?uid=swg21445524

Resolving the problem

In order to allow an Oracle Stored Procedure to pass a result set back to Cognos 8 for further reporting, the Stored Procedure must be part of an Oracle package and use ref cursors to return the result set.

Below is an example of an Oracle Package including a Stored Procedure that would be imported successfully as a Stored Procedure Query Subject into Framework Manager. There are comments in italics included to explain the structure.

create or replace package project_pk as /* Creates Package Header*/
type project_type is record( /* A record declaration is used to */
c1 projects.projectid %TYPE, /* provide a definition of a record */
c2 projects.projecttype %TYPE); /* that can be used by other variables*/
type project_type1 is ref cursor return project_type; /* Variable declaration */
procedure project_sp (tproj IN numeric, result1 in out project_type1); /* SP declaration */
end;
/
create or replace package body project_pk as /* Name of package body must be same as header */
procedure project_sp (tproj IN numeric, result1 in out project_type1) is /* SP Definition */
begin
open result1 for
select projects.projectid, projects.projecttype
from projects
where projects.projecttype=tproj;
end;
end;
/

注意这句话:the Stored Procedure must be part of an Oracle package and use ref cursors to return the result set.

大概意思是:存储过程必须是一个Oracle包和使用动态CURSOR返回的结果集。

完了,原来一般的存储过程(有输出值)FM还识别不了

3.1构建基于package和ref cursor 的procedure

 

复制代码

A:创建package标题
create or replace package king_pk
as /* Creates Package Header*/
type king_type
is record
(
/* A record declaration is used to */
o1 testorder.datekey
%TYPE, /* provide a definition of a record */
o2 testorder.ordercount
%TYPE
);
/* that can be used by other variables*/
type king_type1
is ref cursor return king_type; /* Variable declaration */
procedure king_sp (result1
out king_type1); /* SP declaration */
end;
A:创建package主体
create or replace package body king_pk
as /* Name of package body must be same as header */
procedure king_sp(result1
out king_type1) is /* SP Definition */
begin
open result1
for
select testorder.datekey,testorder.ordercount from testorder
where to_date(datekey,'yyyy-mm-dd')>=to_date(to_char(sysdate-3,'yyyy-mm-dd'),'yyyy-mm-dd')
and to_date(datekey,
'yyyy-mm-dd')<=to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd');
end;
end;

复制代码

 

3.2:查看创建是否成功,失败的话会带红色的×

3.3:OK返回,选择新创建的存储过程

3.4:验证OK,测试OK,数据返回样式和预想一样

PS:需要注意的地方就是,创建包含存储过程的包标题和包体的时候

create or replace package king_pk as /* Creates Package Header*/包标题和包体的名字必须一致
type king_type is record
( /* A record declaration is used to */
o1 testorder.datekey %TYPE, /* provide a definition of a record */   输出对象加上表别名,不然包标题找不到对象就报错
o2 testorder.ordercount %TYPE             
); /* that can be used by other variables*/
type king_type1 is ref cursor return king_type; /* Variable declaration */
procedure king_sp (result1 out king_type1); /* SP declaration */ 
end;

create or replace package body king_pk as /* Name of package body must be same as header */
procedure king_sp(result1 out king_type1) is /* SP Definition */ 包体中存储过程中的参数信息和包标题中的参数信息保持一致
begin
open result1 for
select testorder.datekey,testorder.ordercount from testorder 
where to_date(datekey,'yyyy-mm-dd')>=to_date(to_char(sysdate-3,'yyyy-mm-dd'),'yyyy-mm-dd')
and to_date(datekey,'yyyy-mm-dd')<=to_date(to_char(sysdate,'yyyy-mm-dd'),'yyyy-mm-dd');
end;
end;

先创建包标题,再创建包体,

文终于此,2014-4-23 

推荐 0
本文由 kingwang 创作,采用 知识共享署名-相同方式共享 3.0 中国大陆许可协议 进行许可。
转载、引用前需联系作者,并署名作者且注明文章出处。
本站文章版权归原作者及原出处所有 。内容为作者个人观点, 并不代表本站赞同其观点和对其真实性负责。本站是一个个人学习交流的平台,并不用于任何商业目的,如果有任何问题,请及时联系我们,我们将根据著作权人的要求,立即更正或者删除有关内容。本站拥有对此声明的最终解释权。

0 个评论

要回复文章请先登录注册