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!

Interested in getting your voice heard by members of the Developer Marketing team at Oracle? Check out this post for AppDev or this post for AI focus group information.

Execute procedure after Form -Automatic process DML

Lucas Lima de Araújo BeniNov 27 2024 — edited Nov 27 2024

Hey guys, good evening.

Well, I build a page with a simple DML CRUD

Initially everything works fines, but I receive a new task to order this column with a specific rule, so I did a procedure and calling it from SQL Command it's work to, but I need to run this procedure after submit, so I create a new process as execute code and call the procedure. All DML still work except the procedure, but I'm learning about APEX, SQL, etc… So I delete the process and change the DML Like this:

Testing like this my procedure works, but DML not, if I edit any register and change something no error occur, but the register don't change on table. So consulting GPT I tried to replicate the target type field as region origin, So I did something like this:

And same behaviour happen, no errors, and don't record changes on table.

I've trying another options like create a trigger to call the procedure or even execute the logic, but the logic update items on same table from the submit and error like this happen:
ORA-04091: Table WKSP_SOLUTIS.DAE_BANNER is mutated; the trigger/function may not be able to find it
I'll paste the procedure to show you a complete overview

create or replace PROCEDURE PR_ORDENAR_ORDEM(
  p_id_banner NUMBER,
  p_ordem NUMBER
) AS
  v_id_banner_existente NUMBER;
  v_ordem_anterior NUMBER;
BEGIN
  BEGIN
    SELECT id_banner INTO v_id_banner_existente
    FROM dae_banner
    WHERE ordem = p_ordem
    AND id_banner <> p_id_banner
    AND ordem BETWEEN 1 AND 5;
  EXCEPTION
    WHEN NO_DATA_FOUND THEN
      -- Tratamento para quando não encontrar registro
      NULL;
  END;

  -- Obter a ordem anterior do banner atual
  SELECT ordem INTO v_ordem_anterior
  FROM dae_banner
  WHERE id_banner = p_id_banner;

  -- Cenário 1: Troca direta entre posições válidas
  IF v_ordem_anterior BETWEEN 1 AND 5 THEN
    -- Atualizar o banner que ocupa a nova ordem para a ordem anterior
    UPDATE dae_banner
    SET ordem = v_ordem_anterior
    WHERE id_banner = v_id_banner_existente;

    -- Atualizar o banner atual para a nova ordem
    UPDATE dae_banner
    SET ordem = p_ordem
    WHERE id_banner = p_id_banner;
  ELSE
    -- Cenário 2: Item com ordem 0 movido para uma posição válida
    -- Atualizar o banner atual para a nova ordem
    UPDATE dae_banner
    SET ordem = p_ordem
    WHERE id_banner = p_id_banner;

    -- Deslocar os banners subsequentes (1 a 5) para cima
    UPDATE dae_banner
    SET ordem = ordem + 1
    WHERE ordem >= p_ordem AND ordem <= 5 AND id_banner <> p_id_banner;

    -- Ajustar valores fora do limite (maior que 5)
    UPDATE dae_banner
    SET ordem = 9
    WHERE ordem > 5;
  END IF;

 
END PR_ORDENAR_ORDEM;
/

I'm using APEX 24.1.5, if you guys have some better solution to do this, please teach me how to do it.

Comments
Post Details
Added on Nov 27 2024
3 comments
107 views