Introduction
Updating values from controls into a table is a fundamental operation in Oracle APEX that enables users to modify existing records directly from a form interface. This functionality is often required in applications where users need to review and edit existing data, such as contact details, product information, or status fields. APEX makes it simple to bind form items to database columns, retrieve the current values, and submit changes using a process that automatically updates the underlying table or uses custom PL/SQL.
To update values from controls into a table in Oracle APEX, you typically use a form page that is bound to a table or a custom PL/SQL process. When a user selects a record (e.g., from a report), the page is populated with current values. After editing, the user submits the form, and APEX updates the table using the new input.
Here’s a step-by-step guide to achieve this:
Step 1: Create or Identify the Table to Update
Assume you have the following table:
CREATE TABLE EMPLOYEES (
EMP_ID NUMBER PRIMARY KEY,
EMP_NAME VARCHAR2(100),
EMAIL VARCHAR2(100),
SALARY NUMBER,
LAST_UPDATED DATE
);
Step 2: Create a Form to Edit Records
-
In APEX, go to App Builder > open your app.
-
Click Create > Page.
-
Choose Form > Form on a Table with Report.
-
Select the
EMPLOYEES
table. -
APEX creates:
-
A report page (e.g., Page 1) with a link to edit a row.
-
A form page (e.g., Page 2) to edit selected record.
-
This form automatically includes page items like P2_EMP_NAME
, P2_EMAIL
, P2_SALARY
, and a hidden P2_EMP_ID
.
Step 3: Check or Configure the Automatic Row Fetch and Process
When the user clicks a row in the report:
-
Process: Fetch Row from EMPLOYEES
Automatically loads record into page items on page load. -
Process: Process Row of EMPLOYEES
Automatically updates the table on submit, using the primary key.
Make sure this process has:
-
Type: Automatic Row Processing (DML)
-
Target Type: Table
-
Table Name: EMPLOYEES
-
Primary Key Column: EMP_ID
-
Primary Key Item: P2_EMP_ID
DML Operation: Update
Step 4: Add a Submit Button
This button is used to commit changes:
-
Name:
SAVE
Action: Submit Page
Step 5: Optional – Add a Success Message
In the form page settings:
-
Go to Messages > Success Message
Set to:
Employee record updated successfully.
Step 6: Test the Form
-
Run the application.
-
On the report page, click a row to edit.
-
Change the values in the form.
-
Click
Save
. APEX updates the table using the primary key.
Alternative: Manual Update Using PL/SQL
If you need more control:
-
Create a form manually using page items:
P2_EMP_ID
,P2_EMP_NAME
,P2_EMAIL
, etc. -
Add a button:
Update
-
Add a PL/SQL Process after submit:
UPDATE EMPLOYEES
SET
EMP_NAME = :P2_EMP_NAME,
EMAIL = :P2_EMAIL,
SALARY = :P2_SALARY,
LAST_UPDATED = SYSDATE
WHERE EMP_ID = :P2_EMP_ID;
Only run when Update
button is pressed.
Oracle APEX makes updating table data from form controls straightforward, whether using automatic form processing or writing custom PL/SQL. By connecting page items to database columns and using APEX's built-in fetch/update logic or manual control, you can ensure data is accurately captured and persisted. This approach is ideal for building data management interfaces that are both user-friendly and powerful.
Updating Values from Controls into a Table in Oracle APEX Forms and Reports
Oracle APEX allows users to update database records directly from forms and reports. This tutorial covers updating values using APEX forms, interactive grids, classic reports, and PL/SQL processes.
Updating Values Using APEX Form
Forms in APEX provide a simple way to update existing records.
Step 1: Create a Form Based on a Table
In Oracle APEX, go to your application and click Create Page.
Choose Form and select Form on a Table with Report.
Select the table where data will be updated (e.g., EMPLOYEE_DATA).
Choose Primary Key Column (e.g., EMP_ID).
Click Next, then Finish.
This will generate a report and a form where users can update values.
Step 2: Add an Update Button
Open Page Designer and select the form page.
Locate the Submit Button (Apply Changes).
Under Processing, find the Automatic Row Processing (DML) process.
Ensure it is set to Update the selected record.
When users edit values in the form and click Apply Changes, the record will be updated automatically.
Updating Values Using PL/SQL Process
To manually update values using PL/SQL:
Step 1: Create a Manual Update Process
In Page Designer, go to Processing.
Click Create Process and select PL/SQL Code.
Set When Button Pressed to your update button (e.g., P1_UPDATE).
Use the following PL/SQL code:
BEGIN
UPDATE employee_data
SET emp_name = :P1_EMP_NAME,
emp_email = :P1_EMP_EMAIL,
emp_salary = :P1_EMP_SALARY,
emp_hire_date = TO_DATE(:P1_EMP_HIRE_DATE, 'YYYY-MM-DD')
WHERE emp_id = :P1_EMP_ID;
COMMIT;
END;
This will update the values in the database when the update button is clicked.
Updating Values in an Interactive Grid
Interactive Grids allow users to update multiple records inline.
Step 1: Create an Interactive Grid
In Oracle APEX, go to your application and click Create Page.
Select Report, then Interactive Grid.
Choose the table (EMPLOYEE_DATA) and primary key (EMP_ID).
Click Next, then Finish.
Step 2: Enable Editing in the Interactive Grid
Open Page Designer and select the Interactive Grid Region.
Under Attributes, set Edit Enabled to Yes.
Run the page, edit values directly in the grid, and click Save to update records.
Updating Values Using Classic Reports with Edit Links
If you want users to update records from a classic report:
Step 1: Add an Edit Link to a Classic Report
Open Page Designer and select your Classic Report.
Add a new column for the edit link using the following SQL:
SELECT emp_id,
emp_name,
emp_email,
emp_salary,
emp_hire_date,
'<a href="f?p=&APP_ID.:10:&SESSION.::NO:RP,10:P10_EMP_ID:' || emp_id || '">Edit</a>' AS edit_link
FROM employee_data;
Click Save and Run.
Step 2: Create an Edit Form on Another Page
Create a new form page where users can edit records.
Add a hidden item P10_EMP_ID to store the record ID.
Modify the form to fetch existing values:
SELECT emp_name, emp_email, emp_salary, emp_hire_date
INTO :P10_EMP_NAME, :P10_EMP_EMAIL, :P10_EMP_SALARY, :P10_EMP_HIRE_DATE
FROM employee_data
WHERE emp_id = :P10_EMP_ID;
Add an Update button with a PL/SQL process to update the record.
Now, clicking Edit in the report will open the form with the selected record.
Updating Values Using Dynamic Actions (Without Page Submit)
If you want to update values without submitting the page, use AJAX and Dynamic Actions.
Step 1: Create an AJAX Process
Go to Shared Components > Application Processes.
Create a process named UPDATE_EMPLOYEE_DATA and set Type to PL/SQL AJAX Process.
Use the following code:
BEGIN
UPDATE employee_data
SET emp_name = :P1_EMP_NAME,
emp_email = :P1_EMP_EMAIL,
emp_salary = :P1_EMP_SALARY,
emp_hire_date = TO_DATE(:P1_EMP_HIRE_DATE, 'YYYY-MM-DD')
WHERE emp_id = :P1_EMP_ID;
COMMIT;
END;
Step 2: Create a Dynamic Action
In Page Designer, select the Update Button.
Click Create Dynamic Action and set:
Event: Click
Action: Execute JavaScript
Add the following JavaScript code:
apex.server.process("UPDATE_EMPLOYEE_DATA", {
pageItems: "#P1_EMP_ID, #P1_EMP_NAME, #P1_EMP_EMAIL, #P1_EMP_SALARY, #P1_EMP_HIRE_DATE"
}, {
success: function(data) {
alert("Record updated successfully!");
},
error: function(request) {
alert("Error updating record.");
}
});
This method updates values in real time without refreshing the page.
Best Practices for Updating Data in APEX
Use Forms for Single Record Updates: Best for updating one record at a time.
Use Interactive Grids for Bulk Updates: Best for updating multiple records quickly.
Use Classic Reports with Edit Links: Good for linking reports to an edit form.
Use Dynamic Actions for Live Updates: Best for seamless user experience.
Validate Inputs Before Updating: Prevent errors and invalid data entries.
Oracle APEX provides multiple ways to update records, including forms, interactive grids, classic reports, PL/SQL processes, and AJAX dynamic actions. The best method depends on your application's needs.
EXAMPLE:
We have a dropdown that will display the value in one text box and the display text in a second text box. The goal is t to update the Text from the list by changing the text in the “New Item” text box and saving that in the table.
Step 1 – Add the dropdown list and two text boxes.
Step 2- Add the following settings in the first true branch
The code is as follows
---- This part of the code gets the VALUE from the list and saves it to the 'P48_TESTA_ID_VALUE' text box.
var DisplayValueVar =$("#P48_TESTA_DROPDOWN option:selected").val();
console.log(DisplayValueVar);
apex.item('P48_TESTA_ID_VALUE').setValue(DisplayValueVar);
---- This part of the code gets the TEXT from the list and saves it to the 'P48_NEW_TEXT' text box.
var DisplayTextVar =$("#P48_TESTA_DROPDOWN option:selected").text();
console.log(DisplayTextVar);
apex.item('P48_NEW_TEXT').setValue(DisplayTextVar);
Step 3 – Add the second true branch for saving to the session
The next code saves the information to the session.The code is as follows:
APEX_UTIL.SET_SESSION_STATE('P48_TESTA_ID_VALUE',v('P48_TESTA_ID_VALUE'));
Step 4 – Next add a button with a Dynamic Action and two True Branches
Step 5 – First True branch
Identification > Action: set to Execute Server-side Code
Settings
> Language: PL/SQL
> PL/SQL Code
BEGIN
UPDATE TEST_A
SET VALUEA1 = :P48_NEW_TEXT
WHERE ID = :P48_TESTA_ID_VALUE;
END;
> Items to Submit – This passes the information into the SQL above.
Step 7 – Add a classic report to display the data of the table and set the following values
Step 6 – Set the refresh for the table report
Conclusion
Oracle APEX provides a powerful and flexible way to update table values from form controls. Whether using automated form processes or custom PL/SQL blocks, developers can efficiently capture user changes and apply them to the database. With built-in support for validations, conditions, and user-friendly form elements, updating data becomes a secure and seamless experience that enhances the overall usability of your applications.