有一个业务工作场景,要求我在经典报告中显示有关从 Popup Lov 页面项目中选择的元素的更多信息。经典报告还有一列用于删除在项目中选择的任何元素。 因此,当用户从弹出的 lov 中选择元素时,可以按照以下步骤操作:
Popup Lov Item 是 Form Region 的 item,所有选定的元素都在
group_id
列中处理,这使用户能够执行任何表单操作(创建或插入、保存或更新、删除)。
一般来说,完成此场景所需的组件有:
P100_RECORD_ID
、P100_GROUP_ID
和弹出式 Lov 项目P100_ELEMENTS_CHOICER
Form Initialization
Form - Automatic Row Processing (DML)
on change
与Popup Lov详细...
SELECT
ELEMENTS.ELEMENT_ID AS ELEMENT_ID,
ELEMENTS.OTHER_DATA,
'' AS REMOVE_LINK
FROM ELEMENTS_TABLE ELEMENTS
WHERE element_id IN
(
SELECT TO_NUMBER(TRIM(REGEXP_SUBSTR(input_string, '[^:]+', 1, LEVEL))) AS element_id
FROM (SELECT :P100_ELEMENTS_CHOICER AS input_string FROM DUAL)
CONNECT BY LEVEL <= REGEXP_COUNT(input_string, ':') + 1
)
REMOVE_LINK 列应与以下 URL 值链接:
javascript:apex.event.trigger(apex.gPageContext$, 'customEvent', {element_id:#ELEMENT_ID#});
。
创建自定义事件动态操作,以在单击以下属性的删除链接时触发
Event: Custom
Custom Event: customEvent
Selection Type: Javascript Expression
Javascript Expression: apex.gPageContext$
该 DA 的操作是
Execute Javascript Code
,其中代码是:
var elementToRemove = this.data.element_id
apex.item("P100_ELEMENTS_CHOICER").removeValue(String(elementToRemove))
WITH TEMP AS (
SELECT
GROUP__ID,
LISTAGG(ELEMENT_ID, ':') WITHIN GROUP (ORDER BY ELEMENT_ID) AS ELEMENT_ID
FROM DATA_TABLE
WHERE (:P100_GROUP__ID IS NULL OR GROUP_ID = :P100_GROUP_ID)
GROUP BY GROUP_ID
)
select
TEMP.ELEMENT_ID,
DT.DETAILS,
DT.OTHER_DATA,
DT.GROUP_ID
from DATA_TABLE DT
INNER JOIN TEMP
ON(DT.GROUP_ID = TEMP.GROUP_ID)
FETCH FIRST 1 ROWS ONLY
因此,除了
element_id
之外,此查询的所有数据都应该相同。
P100_ELEMENTS_CHOICER
Popup Lov 项目将 ELEMENT_ID
作为其 List 的返回值。此项目的更改动态操作应具有影响经典报表区域的 refresh
操作。
最后是表格的流程。
Form Initialization
应与默认属性一起使用。 Form - Automatic Row Processing (DML)
的目标类型应为 PL/SQL Code
,并使用以下代码:
DECLARE
V_GROUP_ID DATA_TABLE.GROUP_ID%TYPE;
begin
case :APEX$ROW_STATUS
when 'C' then
SELECT NVL(MAX(GROUP_ID), 0) + 1 INTO V_GROUP_ID FROM DATA_TABLE;
INSERT INTO DATA_TABLE(ELEMENT_ID, DETAILS, OTHER_DATA, GROUP_ID)
WITH ELEMENTS AS (
SELECT TO_NUMBER(TRIM(REGEXP_SUBSTR(input_string, '[^:]+', 1, LEVEL))) AS ELEMENT_ID
FROM (SELECT :P100_ELEMENTS_CHOICER AS input_string FROM DUAL)
CONNECT BY LEVEL <= REGEXP_COUNT(input_string, ':') + 1
)
SELECT ELEMENT_ID, :P100_DETAILS, :P100_OTHER_DATA, V_GROUP_ID
FROM STUDENTS;
when 'U' then
DELETE FROM DATA_TABLE WHERE ELEMENT_ID IN (
SELECT ELEMENT_ID FROM DATA_TABLE DT
LEFT JOIN (
SELECT TO_NUMBER(TRIM(REGEXP_SUBSTR(input_string, '[^:]+', 1, LEVEL))) AS ELEMENT_ID
FROM (SELECT :P100_ELEMENTS_CHOICER AS input_string FROM DUAL)
CONNECT BY LEVEL <= REGEXP_COUNT(input_string, ':') + 1
) NL
ON (DT.ELEMENT_ID = NL.ELEMENT_ID )
WHERE DT.GROUP_ID = TO_NUMBER(:P100_GROUP_ID) AND NL.ELEMENT_ID IS NULL
);
MERGE INTO DATA_TABLE DT
USING (
WITH NEW_ELEMENTS_LIST AS (
SELECT TO_NUMBER(TRIM(REGEXP_SUBSTR(input_string, '[^:]+', 1, LEVEL))) AS STUDENT_ID
FROM (SELECT :P100_ELEMENTS_CHOICER AS input_string FROM DUAL)
CONNECT BY LEVEL <= REGEXP_COUNT(input_string, ':') + 1
) SELECT ELEMENT_ID, :P100_GROUP_ID AS GROUP_VIOLATION_ID FROM NEW_ELEMENTS_LIST) NL
ON (VB.ELEMENT_ID = NL.ELEMENT_ID AND DT.GROUP_ID = NL.GROUP_ID)
WHEN MATCHED THEN
UPDATE SET
DT.DETAILS = :P100_DETAILS,
DT.OTHER_DATA = :P100_OTHER_DATA
WHEN NOT MATCHED THEN
INSERT INTO DATA_TABLE(ELEMENT_ID, DETAILS, OTHER_DATA, GROUP_ID)
VALUES (:P100_DETAILS, NL.ELEMENT_ID, :P100_OTHER_DATA, :P100_GROUP_ID);
when 'D' then
delete DATA_TABLEwhere GROUP_ID = :P100_GROUP_ID;
end case;
正如您在代码中看到的,流程的
DELETE
情况下有 UPDATE
查询,而不是 DELETE
情况,这是因为在 UPDATE
中,用户实际上从弹出 Lov 项目或可以使用表单的其他项目更新已有元素的数据。