如何从与oracle apex中检查的复选框对应的报告中获取值

时间:2015-04-29 10:07:11

标签: oracle-apex

在apex中通过sql命令获取报告后,我想存储与选中的复选框对应的变量sid,serial#的数据。之后我必须在顶点本身执行alter system kill session 'sid,serial#'

1 个答案:

答案 0 :(得分:0)

您好我会在skillbuilders教程中向您展示this使用的方法,该方法基于collections

该方法包括四个步骤,其目的是对集合而不是从一组表格进行报告。我将对所有步骤进行说明,但我强烈建议您在上面的链接中查看视频,了解有关代码的具体详情。

首先您需要使用您的信息创建集合(并将其命名为)    想要在您的报表上显示,为此您将使用查询本身创建一个字符串,然后绑定您可能(或可能不需要)的变量。这是您的收藏模板,请记住,此模板需要根据您的方案进行调整。 在您的情况下,您最感兴趣的是项目#47和#50,这是状态字段(47)和复选框字段(50)。

DECLARE

   l_collection_name APEX_COLLECTIONS.COLLECTION_NAME%TYPE;
   l_bind_names      APEX_APPLICATION_GLOBAL.VC_ARR2;
   l_bind_values     APEX_APPLICATION_GLOBAL.VC_ARR2;
   l_query           VARCHAR2(32767);

BEGIN

   l_collection_name := 'REPLACE_NAME';

   IF apex_collection.collection_exists(l_collection_name)
   THEN
      apex_collection.delete_collection(
         p_collection_name => l_collection_name
      );
   END IF;

   --Query to initialize collection
   --Do not reorder columns later as that could break the values in the tabular form (reorder in report)
   l_query :=
         'SELECT col_1, ' --c001 => f01
      || '   col_2, ' --c002 => f02
      || '   col_3, ' --c003 => f03
      || '   col_4, ' --c004 => f04
      || '   col_5, ' --c005 => f05
      || '   NULL, ' --c006 => f06
      || '   NULL, ' --c007 => f07
      || '   NULL, ' --c008 => f08
      || '   NULL, ' --c009 => f09
      || '   NULL, ' --c010 => f10
      || '   NULL, ' --c011 => f11
      || '   NULL, ' --c012 => f12
      || '   NULL, ' --c013 => f13
      || '   NULL, ' --c014 => f14
      || '   NULL, ' --c015 => f15
      || '   NULL, ' --c016 => f16
      || '   NULL, ' --c017 => f17
      || '   NULL, ' --c018 => f18
      || '   NULL, ' --c019 => f19
      || '   NULL, ' --c020 => f20
      || '   NULL, ' --c021 => f21
      || '   NULL, ' --c022 => f22
      || '   NULL, ' --c023 => f23
      || '   NULL, ' --c024 => f24
      || '   NULL, ' --c025 => f25
      || '   NULL, ' --c026 => f26
      || '   NULL, ' --c027 => f27
      || '   NULL, ' --c028 => f28
      || '   NULL, ' --c029 => f29
      || '   NULL, ' --c030 => f30
      || '   NULL, ' --c031 => f31
      || '   NULL, ' --c032 => f32
      || '   NULL, ' --c033 => f33
      || '   NULL, ' --c034 => f34
      || '   NULL, ' --c035 => f35
      || '   NULL, ' --c036 => f36
      || '   NULL, ' --c037 => f37
      || '   NULL, ' --c038 => f38
      || '   NULL, ' --c039 => f39
      || '   NULL, ' --c040 => f40
      || '   NULL, ' --c041 => f41
      || '   NULL, ' --c042 => f42
      || '   NULL, ' --c043 => f43
      || '   NULL, ' --c044 => f44
      || '   NULL, ' --c045 => f45
      || '   NULL, ' --c046 => f46
      || '   ''O'', ' --c047 (for record status)
      || '   wwv_flow_item.md5(col_1, col_2, col_3, col_4, col_5) ' --c048 (for optimistic locking)
      --c049 for (not used in collection/reserevered for seq_id array)
      --c050 (not used in collection/reservered for delete checkbox array)
      || 'FROM some_table '
      || 'WHERE some_col = :PXX_ITEM_NAME';

   l_bind_names(1) := 'PXX_ITEM_NAME';  
   l_bind_values(1) := v('PXX_ITEM_NAME'); 

   apex_collection.create_collection_from_query_b(
      p_collection_name => l_collection_name,
      p_query           => l_query,
      p_names           => l_bind_names,
      p_values          => l_bind_values
   );

   IF :REQUEST = 'ADD'
   THEN
      apex_collection.add_member(
         p_collection_name => l_collection_name
      );
   END IF;

END;

第二步成功创建集合后,您可以通过直接查询集合来对其进行报告,并使用APEX_ITEM包将您的字段设置为正确的项目,请注意第五项是链接到集合上第50个字段的复选框。再一次,它下面的代码只是一个例子:

SELECT apex_item.hidden(47,c047,NULL,'f47_'|| '#ROWNUM#')
   || apex_item.hidden(48,c048,NULL,'f48_'|| '#ROWNUM#')
   || apex_item.hidden(49,seq_id,NULL,'f49_'|| '#ROWNUM#')
   || apex_item.hidden(1,c001,NULL,'f01_'|| '#ROWNUM#')
   || apex_item.checkbox(
      50, 
      seq_id,
      NULL,
      CASE 
         WHEN c047 = 'D' THEN seq_id
      END,
      ':',
      'f50_' || '#ROWNUM#'
   ) AS delete_checkbox,
   apex_item.text(
      2,
      c002,
      20,
      50,
      NULL,
      'f02_' || '#ROWNUM#'
   ) AS col_2,
   apex_item.text(
      3,
      c003,
      20,
      50,
      NULL,
      'f03_' || '#ROWNUM#'
   ) AS col_3,
   apex_item.select_list_from_lov_xl(
      4,
      NVL(c004, '-1'),
      'NAMED_LOV',
      NULL,
      'YES',
      '-1',
      '- Select Value -',
      'f04_' || '#ROWNUM#'
   ) AS col_4,
   apex_item.select_list_from_lov(
      5,
      NVL(c005, '-1'),
      'NAMED_LOV',
      NULL,
      'YES',
      '-1',
      '- Select Value -',
      'f05_' || '#ROWNUM#'
   ) AS col_5
FROM apex_collections
WHERE collection_name = 'REPLACE_NAME'
ORDER BY c003

第三步那么,现在您有一个集合显示可以在页面中修改的项目,但是否会立即将更改发布到集合中? ...不,你需要先更新集合,因为你有这个代码,这里它处理更新,行创建和行删除。

DECLARE

   l_collection_name APEX_COLLECTIONS.COLLECTION_NAME%TYPE;
   l_original_md5    VARCHAR2(32);
   l_latest_md5      VARCHAR2(32);

BEGIN

   l_collection_name := 'REPLACE_NAME';

   FOR x IN 1 .. apex_application.g_f49.count 
   LOOP         
      IF apex_application.g_f01(x) IS NOT NULL --ID exists, check to see if record was updated
      THEN
         SELECT c048
         INTO l_original_md5
         FROM apex_collections
         WHERE collection_name = l_collection_name
            AND seq_id = apex_application.g_f49(x);

         l_latest_md5 := wwv_flow_item.md5(
            apex_application.g_f01(x),
            apex_application.g_f02(x),
            apex_application.g_f03(x),
            apex_application.g_f04(x),
            apex_application.g_f05(x)
         );

         IF l_original_md5 != l_latest_md5 
         THEN
            apex_collection.update_member(
               p_collection_name => l_collection_name,
               p_seq             => apex_application.g_f49(x),
               p_c001            => apex_application.g_f01(x),
               p_c002            => apex_application.g_f02(x),
               p_c003            => apex_application.g_f03(x),
               p_c004            => apex_application.g_f04(x),
               p_c005            => apex_application.g_f05(x),
               p_c047            => 'U',
               p_c048            => apex_application.g_f48(x)
            );
         END IF;
      ELSE --ID does not exist, must be new record
         apex_collection.update_member(
            p_collection_name => l_collection_name,
            p_seq             => apex_application.g_f49(x),
            p_c001            => apex_application.g_f01(x),
            p_c002            => apex_application.g_f02(x),
            p_c003            => apex_application.g_f03(x),
            p_c004            => apex_application.g_f04(x),
            p_c005            => apex_application.g_f05(x),
            p_c047            => 'N',
            p_c048            => apex_application.g_f48(x)
         );
      END IF;
   END LOOP;

   IF :REQUEST = 'DELETE' 
   THEN
      FOR x IN 1 .. apex_application.g_f50.count 
      LOOP
         apex_collection.update_member_attribute(
            p_collection_name => l_collection_name, 
            p_seq             => apex_application.g_f50(x), 
            p_attr_number     => '47', 
            p_attr_value      => 'D'
         );
      END LOOP;
   END IF;

END;

最后第四步这里我们根据对集合所做的更改来更新表。使用第47和第50个字段,我们知道应更新,删除或创建哪些字段:

DECLARE

   l_table_md5       VARCHAR2(32);
   l_collection_name APEX_COLLECTIONS.COLLECTION_NAME%TYPE;
   l_del_count       PLS_INTEGER := 0;
   l_upd_count       PLS_INTEGER := 0;
   l_ins_count       PLS_INTEGER := 0;
   l_success_message VARCHAR2(32767);

   CURSOR op_lock_check_cur (
      p_id IN NUMBER
   )
   IS
      SELECT wwv_flow_item.md5(col_1, col_2, col_3, col_4, col_5)
      FROM some_table
      WHERE col_1 = op_lock_check_cur.p_id
      FOR UPDATE;

BEGIN

   l_collection_name := 'REPLACE_NAME';

   FOR x IN (
      SELECT *
      FROM apex_collections
      WHERE collection_name = l_collection_name
         AND c047 IN ('N','U','D')
   ) 
   LOOP
      IF x.c047 = 'N'
      THEN
         INSERT INTO some_table(
            col_1,
            col_2,            
            col_3, 
            col_4, 
            col_5
         ) VALUES (
            some_table_seq.nextval, 
            x.c002, 
            x.c003, 
            x.c004, 
            x.c005
         );

         l_ins_count := l_ins_count + 1;
      ELSIF x.c047 = 'U'
      THEN
         --Optimistic lock check
         --MD5 should be identical to collection initialization proc
         OPEN op_lock_check_cur(x.c001);
         FETCH op_lock_check_cur INTO l_table_md5;

         -- Compare the checksum values and if they are different, raise an error.
         IF l_table_md5 != x.c048 
         THEN
            raise_application_error( 
               -20001,
               'Current version of data in database has changed '
               || 'since user initiated update process.'
            );
         END IF;

         UPDATE some_table
         SET col_2 = x.c002,
            col_3 = x.c003,
            col_4 = x.c004,
            col_5 = x.c005
         WHERE CURRENT OF op_lock_check_cur;

         CLOSE op_lock_check_cur;

         l_upd_count := l_upd_count + 1;
      ELSIF x.c047 = 'D'
      THEN
         DELETE FROM some_table
         WHERE col_1 = x.c001;

         l_del_count := l_del_count + 1;
      END IF;
   END LOOP;

   apex_collection.delete_collection(p_collection_name => l_collection_name);

   l_success_message :=  
      l_ins_count || ' rows inserted, ' ||
      l_upd_count || ' rows updated, ' ||
      l_del_count || ' rows deleted';

   :PX_SUCCESS_MESSAGE := l_success_message;

END;

这就是全部,但是从头到脚再次查看教程,有很多我不能在这里发布的信息。

免责声明:我不是技能大师代表,我对视频没有任何权利,我也不会以任何方式推广技能构建者网页。我只是一个程序员,发现本教程很有用。