Skip to Main Content

APEX

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Problem creating a Manual Tabular Form

ranaguirJul 13 2010 — edited Jul 14 2010
Hello, I'm trying to create a manual tabular form. Deleting works ok, but Inserting a new Row doesn't work at all. When I update, I get a No Data Found Error.

This is my code

Process Before Heading:
begin
if apex_collection.collection_exists ('CIP_USUARIO_COMPANIA_COLL') then
apex_collection.delete_collection(p_collection_name => 'CIP_USUARIO_COMPANIA_COLL' );
END IF;
apex_collection.create_collection_from_query(
p_collection_name => 'CIP_USUARIO_COMPANIA_COLL',
p_query => 'Select uc.idfila, uc.k_cod_compania, uc.id_usuario,
''O'' original_flag,
wwv_flow_item.md5(uc.idfila, uc.k_cod_compania, uc.id_usuario)
from ADMCIP.CIP_V_USUARIO_COMPANIA uc
where uc.id_usuario = ''' || :P3_K_ID_USUARIO || '''',
p_generate_md5 => 'YES');
end;

Report:
Select apex_item.hidden(1, c001) idfila,
apex_item.select_list_from_query(2, c002,
'select nom_compania, k_cod_compania
from ADMCIP.CIP_COMPANIA
order by 1 asc', 10) k_cod_compania,
apex_item.hidden(3, c003) id_usuario,
apex_item.hidden(11, c004) status,
apex_item.checkbox(12, seq_id) chkbx,
apex_item.hidden(13, seq_id) seq_id
from APEX_COLLECTIONS
where collection_name = 'CIP_USUARIO_COMPANIA_COLL' and
c004 IN ('O','N','U') -- no deletes
UNION ALL
Select apex_item.hidden(1, null) idfila,
apex_item.select_list_from_query(2, null,
'select nom_compania, k_cod_compania
from ADMCIP.CIP_COMPANIA
order by 1 asc', 10) k_cod_compania,
apex_item.hidden(3, null) id_usuario,
apex_item.hidden(11, null) status,
apex_item.checkbox(12, null) chkbx,
apex_item.hidden(13, null) seq_id
from DUAL

Process for creating a new row:
declare
l_status varchar2(1);
begin
l_status := 'N';
for i in 1 .. apex_application.g_f01.count loop
if apex_application.g_f01(i) is null then
apex_application.g_f13(i) := apex_collection.add_member(p_collection_name => 'CIP_USUARIO_COMPANIA_COLL',
p_c001 => apex_application.g_f01(i),
p_c002 => apex_application.g_f02(i),
p_c003 => apex_application.g_f03(i),
p_c004 => l_status,
p_generate_md5 => 'YES');
end if;
end loop;
end;

Process for Updating Collection:
declare
l_status varchar2(1);
l_seq_id number;
l_original_md5 varchar2(4000);
l_array_md5 varchar2(4000);
l_exists boolean := false;
begin
--
--:P3_MENSAJE := 'Entrando a Actualiza_Coleccion.';
--:P3_MENSAJE := :P3_MENSAJE || ' Count=' || to_char(apex_application.g_f01.count);
for i in 1 .. apex_application.g_f01.count loop
--:P3_MENSAJE := :P3_MENSAJE || ' i=' || to_char(i);
--:P3_MENSAJE := :P3_MENSAJE || ' g_f13(i)=' || apex_application.g_f13(i);
if apex_application.g_f13(i) is not null then
begin
Select c004, c005 -- las variables en las que se guardaron el status y el MD5
-- de acuerdo con el orden de la creacion de la coleccion
into l_status, l_original_md5
from apex_collections
where collection_name = 'CIP_USUARIO_COMPANIA_COLL' and
seq_id = apex_application.g_f13(i);
EXCEPTION
when OTHERS then
:P3_MENSAJE := 'Error en Select #1';
end;
--
-- For existing rows only
-- 1. calculate the new md5
-- 2. if md5 changed, set status to 'U'
-- For new or updated rows, update collection
--
--
-- For existing rows: create an mad5 calculation and if it is different from original md5 calculation, set it status to U
--
if l_status <> 'N' then
-- calcula el MD5 de la informacion de la forma tabular
Select wwv_flow_item.md5(apex_application.g_f01(i),
apex_application.g_f02(i),
apex_application.g_f03(i))
into l_array_md5
from DUAL;
if l_original_md5 != l_array_md5 then -- compara y determina si hubo cambio
l_status := 'U';
end if;
end if;
--
-- For new or updated rows: update the collection member
--
if l_status in ('N', 'U') then
-- si hubo cambio actualiza
apex_collection.update_member(p_collection_name => 'CIP_USUARIO_COMPANIA_COLL',
p_seq => apex_application.g_f13(i),
p_c001 => apex_application.g_f01(i),
p_c002 => apex_application.g_f02(i),
p_c003 => apex_application.g_f03(i),
p_c004 => l_status,
p_c005 => l_original_md5);
end if;
end if;
end loop;
--
-- DELETE EMPLOYEE - if employee was added, delete member from collection
-- if employee already existed, set status to 'D'
--
if :REQUEST = 'DELETE_UC' then -- si es un borrado
for i in 1 .. apex_application.g_f12.count loop
if apex_application.g_f12(i) is not null then -- si el registro esta seleccionado
:p3_num_deleted := :p3_num_deleted + 1; -- incrementa la cantidad de borrados
-- selecciona la secuencia y el estado en la coleccion
Select seq_id, c004
into l_seq_id, l_status
from wwv_flow_collections
where collection_name = 'CIP_USUARIO_COMPANIA_COLL' and
seq_id = apex_application.g_f12(i);
if l_status = 'N' then
-- si es un registro nuevo, nada mas lo borra
apex_collection.delete_member(p_collection_name => 'CIP_USUARIO_COMPANIA_COLL',
p_seq => l_seq_id);
else
-- si no es un registro nuevo, entonces cambia el estado a borrado
apex_collection.update_member_attribute(p_collection_name => 'CIP_USUARIO_COMPANIA_COLL',
p_seq => l_seq_id,
p_attr_number => '4',
p_attr_value => 'D');
end if;
end if;
end loop;
end if;
--
-- Set the success message -- cambia el mensaje de acuerdo a si hubieron borrados
--
if to_number(:p3_num_deleted) > 0 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
:p3_num_deleted;
if to_number(:p3_num_deleted) = 1 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Compania Borrada';
else
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Companias Borradas';
end if;
end if;
end;

Process for Updating Database:
declare
l_table_md5 varchar2(4000);
l_array_md5 varchar2(4000);
l_collection_md5 varchar2(4000);
begin
:p3_num_updated := 0;
:p3_num_added := 0;
:p3_num_deleted := 0;
for c1 in (Select c001, c002, c003, c004, c005, seq_id
from apex_collections
where collection_name = 'CIP_USUARIO_COMPANIA_COLL') loop
--
-- New - insert it
--
if c1.c004 = 'N' then
:P3_NUM_ADDED := :P3_NUM_ADDED + 1;
Insert into ADMCIP.CIP_V_USUARIO_COMPANIA (k_cod_compania, id_usuario)
values (c1.c002, c1.c003);
--
-- Delete row
--
elsif c1.c004 = 'D' then
Delete from ADMCIP.CIP_V_USUARIO_COMPANIA uc
where uc.idfila = c1.c001;
--
-- Update changed row
--
elsif c1.c004 = 'U' then
Select wwv_flow_item.md5(idfila, k_cod_compania, id_usuario)
into l_table_md5
from ADMCIP.CIP_V_USUARIO_COMPANIA uc
where uc.idfila = c1.c001;
if l_table_md5 != c1.c005 then
raise_application_error(-20001,
'Current version of data in database has changed since user initiated update process.');
return;
end if;
Select wwv_flow_item.md5(c1.c001, c1.c002, c1.c003)
into l_array_md5
from dual;
if c1.c005 <> l_array_md5 then
:p3_num_updated := :p3_num_updated + 1;
Update ADMCIP.CIP_V_USUARIO_COMPANIA uc
set uc.k_cod_compania = c1.c002,
uc.id_usuario = c1.c003
where uc.idfila = c1.c001;
end if;
end if;
end loop;
--
-- Set Success Message
--
if to_number(:p3_num_updated) > 0 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
:p3_num_updated;
if to_number(:p3_num_updated) = 1 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Employee Updated';
else
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Employees Updated';
end if;
end if;
if to_number(:p3_num_deleted) > 0 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
:p3_num_deleted;
if to_number(:p3_num_deleted) = 1 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Employee Deleted';
else
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Employees Deleted';
end if;
end if;
if to_number(:P3_NUM_ADDED) > 0 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
:P3_NUM_ADDED;
if to_number(:P3_NUM_ADDED) = 1 then
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Employee Added';
else
apex_application.g_print_success_message := apex_application.g_print_success_message ||
' Employees Added';
end if;
end if;
--
-- Clean up: delete collection
--
apex_collection.delete_collection(p_collection_name => 'CIP_USUARIO_COMPANIA_COLL');
end;
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Aug 11 2010
Added on Jul 13 2010
2 comments
786 views