Oracle Apex多选LOV在历史表中分隔的数值

huangapple go评论109阅读模式
英文:

Oracle Apex multi select lov separated values in history table

问题

我有一个带有多选字段 - BONUS_TYPE 的交互式网格
数据库列:BONUS_TYPE_ID NUMBER

网格查询是:select EMP_NAME,DESIGNATION,BONUS_TYPE_ID FROM EMP_BONUS_UPDATES;

它是一个带有允许多选选项的弹出式LOV。

弹出式的选择查询是:
select bonus_type_name a, bonus_id from BONUS_DATA;

BONUS_DATA表:

BONUS_TYPE    
BONUS_TYPE_NAME    BONUS_ID
MILESTONE    1
REFERRAL    2

在交互式网格中,例如EMP John的值显示为:MILESTONE:REFERRAL
而对于Andrew,只显示为MILESTONE

在数据库中,它们保存为相应的ID:1:2和1分别。

问题是我在EMP_BONUS_UPDATES表上有一个触发器,用于在插入-更新时将列数据(旧值和新值)存储在历史表中。

对于这个特定的列:BONUS_TYPE_ID,数据被正确地存储,但我需要生成一个报告。

在多选之前,数据显示正常,但现在只显示ID而不是名称,这是显而易见的。

如何编写查询以在报告中显示冒号分隔的名称而不是ID。

HISTORY        
COLUMN    OLD    NEW
BONUS_TYPE_ID    1    1:2

现在是多选,我如何在报告中显示显示值而不是ID。

--历史表查询

 select column, case when column ='BONUS_TYPE_ID' then (select bonus_type_name from bonus_Data where bonus_id =old)
    else old end old, 
    case when column ='BONUS_TYPE_ID' then (select bonus_type_name from bonus_Data where bonus_id =new)
    else new end new
    from BONUS_HISTORY;
英文:

I have an Interactive grid with a multi select field - BONUS_TYPE
Database column: BONUS_TYPE_ID NUMBER

Grid query is: select EMP_NAME,DESIGNATION,BONUS_TYPE_ID FROM EMP_BONUS_UPDATES;

It is a POP-UP LOV with allow_multi select option.

The select query for pop-up is:
select bonus_type_name a, bonus_id from BONUS_DATA;

BONUS_DATA Table:

BONUS_TYPE	
BONUS_TYPE_NAME	BONUS_ID
MILESTONE	1
REFERRAL	2

In IG values for say EMP John show as: MILESTONE:REFERRAL
and for Andrew as just MILESTONE

In DB, they are saved as corresponding ID's.
1:2 and 1 respectively.

The problem is i have a trigger on the EMP_BONUS_UPDATES table which upon insert-update stores column data (old and new) values in history table.

For this specific column: BONUS_TYPE_ID data is being stored fine but i need to pull up a report.

Before multi select, the data was showing fine but now it is just showing as IDs and not the names obviously.

How can i write query to pull names with colon separators instead of id's.

HISTORY		
COLUMN	OLD	NEW
BONUS_TYPE_ID	1	1:2

Instead of 1 and 1:2 , now that it's multi select, how do i show the displayvalues in the report?

--History table query

 select column, case when column ='BONUS_TYPE_ID' then (select bonus_type_name from bonus_Data where bonus_id =old)
    else old end old, 
    case when column ='BONUS_TYPE_ID' then (select bonus_type_name from bonus_Data where bonus_id =new)
    else new end new
    from BONUS_HISTORY;

答案1

得分: 1

以下是翻译好的部分:

这里有一个选项;在代码中阅读注释:

示例数据:

SQL> 使用
-- 所有奖金类型的表
奖金类型(bonus_id,bonus_type_name)为
(从双重选择1,'milestone'的选择
从双重选择2,'推荐' 从双重选择
),
-- 这是一个包含冒号分隔的ID的表
-- 多个选择的值
emp_bonus_updates(some_id,bonus_type_id)为
(从双重选择100,'1'的选择 -->仅选择了1个值
从双重选择101,'1:2'的选择 -->选择了2个值

实际查询从这里开始:

13选择x.some_id,
-- 聚合奖金类型名称
listagg(bt.bonus_type_name,':')在组内(按null排序)结果
从奖金类型bt加入
-- 将冒号分隔的值拆分成行,以便将它们连接到BONUS_TYPE ID
(从双重选择some_Id,
regexp_substr(bonus_type_id,'[^:]+',1,column_value)bti
从emp_bonus_updates交叉连接
表(多重集(选择级别从双重选择开始
按等于regexp_count(bonus_type_id,':')+ 1计算
)作为sys.odcinumberlist))
)x
在x.bti = bt.bonus_id上
按x.some_id分组。

SOME_ID RESULT
---------- ------------------------------
100里程碑
101里程碑:推荐

SQL>

或者,由于您使用Apex,另一个选项是使用apex_string.split

13选择e.some_id,
listagg(b.bonus_type_name,':')在组内(按null排序)结果
从emp_bonus_updates e交叉连接表(apex_string.split(e.bonus_type_id,':'))x
加入奖金类型b b.bonus_id = x.column_value;
从emp_bonus_updates e交叉连接表(apex_string.split(e.bonus_type_id,':'))x

Oracle Apex多选LOV在历史表中分隔的数值


<details>
<summary>英文:</summary>

Here&#39;s one option; read comments within code:

Sample data:

    SQL&gt; with
      2  -- table of all bonus types
      3  bonus_type (bonus_id, bonus_type_name) as
      4    (select 1, &#39;milestone&#39; from dual union all
      5     select 2, &#39;referral&#39;  from dual
      6    ),
      7  -- this is a table which - in BONUS_TYPE_ID - contains colon-separated ID
      8  -- values for multiple selections
      9  emp_bonus_updates (some_id, bonus_type_id) as
     10    (select 100, &#39;1&#39;   from dual union all    --&gt; only 1 value has been selected
     11     select 101, &#39;1:2&#39; from dual              --&gt; 2 values selected
     12    )

Actual query begins here:

     13  select x.some_id,
     14    -- aggregate bonus type names
     15    listagg(bt.bonus_type_name, &#39;:&#39;) within group (order by null) result
     16  from bonus_type bt join
     17    -- split colon-separated values into rows so that you could join them to BONUS_TYPE IDs
     18    (select some_Id,
     19       regexp_substr(bonus_type_id, &#39;[^:]+&#39;, 1, column_value) bti
     20     from emp_bonus_updates cross join
     21       table(cast(multiset(select level from dual
     22                           connect by level &lt;= regexp_count(bonus_type_id, &#39;:&#39;) + 1
     23                          ) as sys.odcinumberlist))
     24    ) x
     25    on x.bti = bt.bonus_id
     26  group by x.some_id;
    
       SOME_ID RESULT
    ---------- ------------------------------
           100 milestone
           101 milestone:referral
    
    SQL&gt;

---------------

Or, as you use Apex, another option which utilizes `apex_string.split`:

     13  select e.some_id,
     14    listagg(b.bonus_type_name, &#39;:&#39;) within group (order by null) result
     15  from emp_bonus_updates e cross join table(apex_string.split(e.bonus_type_id, &#39;:&#39;)) x
     16  join bonus_type b on b.bonus_id = x.column_value;
    from emp_bonus_updates e cross join table(apex_string.split(e.bonus_type_id, &#39;:&#39;)) x

[![enter image description here][1]][1]


  [1]: https://i.stack.imgur.com/tgmez.png

</details>



huangapple
  • 本文由 发表于 2023年7月23日 22:50:11
  • 转载请务必保留本文链接:https://go.coder-hub.com/76748873.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定