Oracle BI Publisher,select 个不同的列(按参数)

Oracle BI Publisher, select different columns by parameter

我刚开始使用 Oracle BI Publisher,我真的不知道如何完成我的任务。

我的项目是向用户询问一个参数(没关系),如果用户选择 01,我应该只显示 'january' 和一些数据。如果用户选择 03,我应该显示 3 列,'january' 'february' 'march',每列都有一些数据。

我拥有 12 月之前的所有列,我只是不知道如何根据给定参数 select 不同数量的列。

已编辑,添加了代码!

declare
p SYS_REFCURSOR;

begin

if (:month)=02 then
open p for select 'bazisev' as evtipus, month-1 as month, january, february
    from db.tablename where month=(:month)-1 and sorszam between 4 and 15
  union all
  select 'targyev' as evtipus, month, january, february 
    from db.tablename where month=(:month) and sorszam between 4 and 15
  union all
  select 'targyev/bazisev' as evtipus, month, january, february
    from db.tablename where month=(:month) and sorszam between 32 and 39 
  order by sorszam;

elsif (:month)=01 then

open p for select 'bazisev' as evtipus, month-1 as month, january
    from db.tablename where month=(:month)-1 and sorszam between 4 and 15
  union all
  select 'targyev' as evtipus, month, january
    from db.tablename where month=(:month) and sorszam between 4 and 15
  union all
  select 'targyev/bazisev' as evtipus, month, january
    from db.tablename where month=(:month) and sorszam between 32 and 39 
  order by sorszam;

end if;

end

所以现在我用了 2 个月就这样做了,但它说:ORA-00907:缺少右括号

我很确定我有我需要的所有括号。有什么建议吗?

if the user chooses 01, I should display ONLY 'january' with some data. If the user chooses 03, I should display 3 columns, 'january' 'february' 'march' with some data in each.

纯 SQL 中不能有动态列。您需要使用 EXECUTE IMMEDIATE 以编程方式 (ab) 执行此操作。在 IF-ELSE 构造中,准备 动态 SQL 然后根据 输入值 .[=14 执行它=]

伪代码:你需要注意输出类型。

DECLARE
   v_str VARCHAR2(2000);
BEGIN
   IF :id = 1
      THEN v_str := 'SELECT january FROM table_name';
   ELSIF :id = 2
      THEN v_str := 'SELECT january, february FROM table_name';
   ELSIF...
   .
   .
   .
   ELSIF :id = 12
      THEN v_str := 'SELECT january, february...,december FROM table_name';
   END IF;

   EXECUTE IMMEDIATE v_str...
END;

另一种方法是使用 REFCURSOR。例如,

DECLARE

r SYS_REFCURSOR;

BEGIN
   IF :id = 1
      THEN open r for SELECT january FROM table_name;
   ELSIF :id = 2
      THEN open r for SELECT january, february FROM table_name;
   ELSIF...
   .
   .
   .
   ELSIF :id = 12
      THEN open r for SELECT january, february...,december FROM table_name';
   END IF;
END;