Search code examples
oracle-apexoracle-apex-5oracle-apex-5.1

How to show alert if user tries to save values, that are already present my table for my Oracle Apex Form based application


I have a form in my Oracle APEX based application, I want to have validation on submit button, so that the combination of two specific entries, if they already are present in the SQL table/View, I want to show an alert, like "The entry for this combination of values of A and B already exists, please enter correct values."


Solution

  • If those two specific entries are represented by two form items (e.g. :P1_ONE and :P2_TWO), then the validation procedure might be a function that returns error text, such as

    declare
      l_cnt number;
      retval varchar2(200);
    begin
      select count(*)
        into l_cnt
        from your_table t
        where t.column_one = :P1_ONE
          and t.column_two = :P1_TWO;
    
      if l_cnt > 0 then 
         retval := 'The entry for this combination already exists';
      end if;
    end;
    

    The query itself might need to be modified, depending on what exactly you meant by describing the problem; that's the way I understood it.