在Oracle Apex的表格形式中,您如何才能更新已检查的行,您将在何处放置此流程?
您是否将其作为条件添加到现有的ApplyMRU流程中?
我目前只是在我有表格形式的地方,我只希望它更新已检查的行,然后发送电子邮件,让人们知道该记录的状态已经改变。
我尝试过基于时间和日期的建议来做这件事,但它发出的每一条记录只是我需要的那些。
这是当前无法正常工作的电子邮件代码,我不想直接从表中提取它,我宁愿使用表格表单上的字段,只通过电子邮件发送已经检查过的行。
DECLARE
l_id NUMBER;
l_index NUMBER;
l_vc_arr2 apex_application_global.vc_arr2;
lc_message VARCHAR2 (4000);
l_pkey NUMBER;
l_date_wrote DATE;
l_sales VARCHAR2 (4000);
l_client VARCHAR2 (4000);
l_job VARCHAR2 (4000);
l_who VARCHAR2 (4000);
l_date_covered DATE;
BEGIN
FOR c1
-- Retrieve reqs primary key that have been covered
-- in the last 2 seconds by the salesman
IN (SELECT pkey
FROM reqs
WHERE TO_CHAR ( (SYSDATE), 'MM/DD/YYYY HH:MI:SS') < (TO_CHAR ( (date_covered + 1 / 10800), 'MM/DD/YYYY HH:MI:SS'))
AND sales = :p14_sales
AND covered IS NOT NULL)
-- Send an email for each req that has been covered
LOOP
SELECT date_wrote,
sales,
client,
job,
Who,
date_covered
INTO l_date_wrote,
l_sales,
l_client,
l_job,
l_who,
l_date_covered
FROM reqs
WHERE pkey = c1.pkey;
lc_message := 'Date Written :' || l_date_wrote || CHR (10);
lc_message := lc_message || 'Sales :' || l_sales || CHR (10);
lc_message := lc_message || 'Client :' || l_client || CHR (10);
lc_message := lc_message || 'Position :' || l_job || CHR (10);
lc_message := lc_message || 'Who Covered :' || l_who || CHR (10);
lc_message := lc_message || 'Date Covered :' || l_date_covered || CHR (10);
l_id := APEX_MAIL.SEND(
p_to => 'some.name@somedomain.com',
p_from => 'DO_NOT_REPLY@REQS',
p_subj => ''
|| l_who
|| ' Has Covered '
|| l_job
|| ' at '
|| l_client
|| CHR (10),
p_body => lc_message);
COMMIT;
apex_mail.push_queue ();
END LOOP;
END;
我一直在用这个墙撞墙。
谢谢!
答案 0 :(得分:2)
您需要使用PLSQL循环遍历正确的数组。表格形式的项目映射到会话状态中的几个数组
Apex documentation: Referencing Arrays
复选框是特殊情况,因为它们在未选中时不会在这些数组中创建条目
Apex documentation: Referencing Arrays in an on-submit process
例如,我在EMP上有一个表格形式,并且有一个“[row selector]”列。
在网页上:
然后我有这个提交过程:
-- loop over array f01
-- this will be the array holding the values for a checkbox column (in this case, the row selector pseudo column)
FOR i IN 1..apex_application.g_f01.count
LOOP
-- show what is in array f01
-- this will be the index position of the checked row in case of the row selector
apex_debug.message('Value of array f01 at position'||i||': '||apex_application.g_f01(i));
-- array f02 will be the next editable (or session state saving) column, in my case a display-but-session-state-saving column with the EMPNO
apex_debug.message('Value of array f02 at position'||apex_application.g_f01(i)||': '||apex_application.g_f02(apex_application.g_f01(i)));
END LOOP;
调试中的输出:
Value of array f01 at position1: 2
Value of array f02 at position2: 7698
Value of array f01 at position2: 4
Value of array f02 at position4: 7566
所以需要注意的事项:
这些是在使用the APEX_ITEM api的手动表格形式时非常常用的技术。
因此,要使您的电子邮件系统正常工作:遍历复选框列,从另一个阵列中检索PK,并像在当前循环中一样发送邮件。
例如:
我拿了你的代码样本并对其进行了调整。请注意,我更改了一些内容:
DECLARE
l_checked_row NUMBER;
l_id NUMBER;
lc_message VARCHAR2 (4000);
l_pkey NUMBER;
l_r_reqs reqs%ROWTYPE;
BEGIN
FOR i IN 1..apex_application.g_f01.count
LOOP
l_checked_row := apex_application.g_f01(i);
-- assuming that array F02 maps to column PKEY from table REQS
l_pkey := apex_application.g_f02(l_checked_row);
-- get details required for creating the mail body
-- It's generally easier to just fetch the row instead of having to
-- define variables to cover every field you need.
SELECT *
INTO l_r_reqs
FROM reqs
WHERE pkey = l_pkey;
-- Dont forget that select into may generate no_data_found or too_many_rows !
lc_message := 'Date Written :' || l_r_reqs.date_wrote || CHR (10);
lc_message := lc_message || 'Sales :' || l_r_reqs.sales || CHR (10);
lc_message := lc_message || 'Client :' || l_r_reqs.client || CHR (10);
lc_message := lc_message || 'Position :' || l_r_reqs.job || CHR (10);
lc_message := lc_message || 'Who Covered :' || l_r_reqs.who || CHR (10);
lc_message := lc_message || 'Date Covered :' || l_r_reqs.date_covered || CHR (10);
l_id := APEX_MAIL.SEND(
p_to => 'TESTER@TEST.com',
p_from => 'DO_NOT_REPLY@REQS',
p_subj => ''
|| l_r_reqs.who
|| ' Has Covered '
|| l_r_reqs.job
|| ' at '
|| l_r_reqs.client
|| CHR (10),
p_body => lc_message);
-- avoid commits unless ab-so-lu-te-ly necessary. Apex implicit commits can make the flow hard enough to
-- understand as it is.
END LOOP;
apex_mail.push_queue ();
END;