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.

APEX 5.1 How to manually process Interactive Grid data using PL/SQL

pkpandaJun 5 2016 — edited Jun 8 2016

Hi

I am trying APEX 5.1 interactive grid, I don't want the automated row update instead I want to have my own pl/sql procedure to insert or update record in table. How do I get the changed record values? can I use the same APEX_APPLICATION.G_F0 or anything new.

Thanks

This post has been answered by Patrick Wolf-Oracle on Jun 6 2016
Jump to Answer

Comments

Bharat G

Yes we can use APEX_APPLICATION.G_F0 to insert or update the records.

As we have Tabular form to do this, what is the problem with it ?

pkpanda

Hi Bharat,

I am talking about tabular form I am asking about the new Interactive Grid and the element is contracted differently then standard tabular form. Did you try this?

Patrick Wolf-Oracle
Answer

Hi,

if you want to execute your own insert/update/delete or PL/SQL api calls for all the modified rows of an Interactive Grid you can do this with the "Save Interactive Grid Data / Interactive Grid Automatic Row Processing (DML)" process which gets automatically created when you make an Interactive Grid editable.


Here is an example if your Interactive Grid is based on EMP.


Settings for your Region:


Source > SQL Query =

select empno, ename, deptno

  from emp


Attributes > Edit > Enabled = Yes


Settings for your Save Interactive Grid Data process:


Settings > Set Target Type = PL/SQL Code

Settings > PL/SQL Code to Insert/Update/Delete =

begin

     case :APEX$ROW_STATUS

     when 'I' then -- Note: In EA2 this has been changed from I to C for consistency with Tabular Forms

         insert into emp ( empno, ename, deptno )

         values ( :EMPNO, :ENAME, :DEPTNO )

         returning rowid into :ROWID;

     when 'U' then

         update emp

            set ename  = :ENAME,

                deptno = :DEPTNO

          where rowid  = :ROWID;

     when 'D' then

         delete emp

         where rowid = :ROWID;

     end case;

end;

The PL/SQL code is very similar to what you can use for Tabular Forms if you have defined a PL/SQL process which fires for a Tabular Form region. It will be executed for each modified row, the bind variable APEX$ROW_STATUS can be used to find out if the row has been inserted, updated or deleted and bind variables can be used to reference the value of all columns of the Interactive Grid. Please be aware, that the bind variables will still return a string, so be careful in case of numbers and dates.

Note: If your INSERT statement or your PL/SQL API call generates a primary key as it's the case with the ROWID, you have to assign the result to the primary key column again. In the above case I'm using a RETURNING clause to do so. This is important, because that primary key value is used to query the newly inserted data. Only in the case if the end user enters a primary key value then this is not necessary.

I will update the "PL/SQL Code to Insert/Update/Delete" attribute to contain an example.

Hope that gives an idea

Patrick

Marked as Answer by pkpanda · Sep 27 2020
Sven W.

Awesome! That is much easier than the current (old) way using apex_collections.

Test2

Thanks Patrick,

So, does it mean that IG can handle DML on more than one table ?

Patrick Wolf-Oracle

Yes, you can do whatever you want to do in your PL/SQL code. An alternative to the PL/SQL code option is to use standard IG DML processing and use a database view with an instead of trigger.

Regards

Patrick

pkpanda

Thank you very much. I hope this pl/sql block will iterate for all the rows in the IG.

Jozef Demovic SVK

Hi Patrick,

just one small thing.

Is there some new :APEX$ROW_STATUS value for insert like 'I' ?

I can see just 'C' for created rows in documentation. May I use 'I' or 'C' instead ?

(just for those who should try your PL/SQL block)

Thanks

regards

J

Patrick Wolf-Oracle

Hi,

yes it's called for each modified row.

Regards

Patrick

Patrick Wolf-Oracle

Hi Jozef,

indeed, tabular forms currently use 'C' for new rows and IG is using 'I' instead. May I ask you to file an EA1 feedback. I think this should be unified to make migration easier.

Regards

Patrick

Jozef Demovic SVK

Thanks Patrick,

I'll fill the EA1 feedback. Unified is better 

regards

J

Patrick Wolf-Oracle

This has been changed from I to C in development and will be available next time the Early Adopter is fully refreshed.

Regards

Patrick

1 - 12
Locked Post
New comments cannot be posted to this locked post.

Post Details

Locked on Jul 6 2016
Added on Jun 5 2016
12 comments
84,288 views