Skip to Main Content
  • Questions
  • insert only value of rows which has data from tabular form into database

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Maqsadullah.

Asked: August 18, 2016 - 12:31 pm UTC

Last updated: August 19, 2016 - 7:43 am UTC

Version: apex 5

Viewed 1000+ times

You Asked

Hello
can you please help me how to create a PL/SQL process to insert only rows which has values from tabular form into database,not those rows which does not have value, below is the insert PL/SQL process that i created, but it insert empty rows also, which did not have value.


begin

FOR i in 1..APEX_APPLICATION.G_F05.COUNT LOOP

IF APEX_APPLICATION.G_F05(i) > 1 THEN
insert into TBL_MEETING_LOAN (PROFIT) values (:DERIVED$05);
END IF;

END LOOP;

End;



please check below pictures.

values while entry.
http://i.stack.imgur.com/D49DS.jpg


database after insert.
http://i.stack.imgur.com/Yfu1Y.jpg

and Chris said...

I'm not familiar enough with APEX to know if there's a better way do to this using in-built functionality.

But the way to avoid inserting null values in PL/SQL is easy:

Just check whether the value is null or not!

begin

  FOR i in 1..APEX_APPLICATION.G_F05.COUNT LOOP

    IF APEX_APPLICATION.G_F05(i) > 1 AND :DERIVED$05 IS NOT NULL THEN
      insert into TBL_MEETING_LOAN (PROFIT) values (:DERIVED$05);
    END IF;

  END LOOP;

End;
/


Or, even better, change the loop to a bulk insert:

begin

  forall i in 1..apex_application.g_f05.count 
    insert into tbl_meeting_loan (profit) 
      select :derived$05
      from   dual
      where  apex_application.g_f05(i) > 1 
      and    :derived$05 is not null;
    
end;
/

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

it worked

Maqsadullah Qarizada, August 22, 2016 - 5:06 am UTC

Thank you very much "Chris Saxon" your code worked, thank you very much.