Search This Blog

Saturday, July 12, 2025

How do I ADD values from 2 controls into table

Introduction
Adding values from two form controls into a table in Oracle APEX is a common requirement when capturing user input across multiple fields. Whether you're entering product details, capturing a name and email, or logging coordinates, the process involves creating input items on a page and using a submit process to store those values in the database. With Oracle APEX, this can be achieved using either declarative features or a custom PL/SQL block, making it simple to integrate into both basic and complex applications.

 To add values from two controls into a table in Oracle APEX, you use page items (form fields), a submit button, and a process that takes the values from those items and inserts them into a target table. This is a common scenario for capturing basic data like a name and email, or a code and description.

Here’s a detailed step-by-step process:

Step 1: Create the Table (if it doesn’t exist)

First, define the table that will store the values. For example:

CREATE TABLE CONTACT_LOG (
  ID        NUMBER GENERATED BY DEFAULT ON NULL AS IDENTITY PRIMARY KEY,
  FULL_NAME VARCHAR2(100),
  EMAIL     VARCHAR2(100),
  CREATED_AT DATE DEFAULT SYSDATE
);

Step 2: Create a Page in Oracle APEX

  1. Open your application in App Builder.

  2. Click Create > Page.

  3. Choose Blank Page.

  4. Name the page (e.g., “Add Contact Info”).

Step 3: Add Form Controls (Page Items)

In the page designer:

  • Under a region (e.g., "Contact Form"), add two page items:

    • P1_FULL_NAME – Type: Text Field – Label: Full Name

    • P1_EMAIL – Type: Text Field – Label: Email

These will be the input controls.

Step 4: Add a Button to Submit

  1. Under the same region or a new one, add a button:

    • Name: SAVE

    • Label: Save

    • Action: Submit Page

Step 5: Add a PL/SQL Process to Insert the Values

  1. In the Processing section, click “+” to add a new Process.

  2. Name: Insert Contact Log

  3. Type: PL/SQL Code

  4. Point: After Submit

  5. When Button Pressed: SAVE

PL/SQL Code:

INSERT INTO CONTACT_LOG (FULL_NAME, EMAIL)
VALUES (:P1_FULL_NAME, :P1_EMAIL);

Step 6: Add a Success Message (Optional)

In the Messages section of the page:

  • Success Message: Contact saved successfully.

Step 7: Run and Test

  1. Run the application.

  2. Enter values in the Full Name and Email fields.

  3. Click Save.

  4. The record is inserted into the CONTACT_LOG table.

Optional: Clear Form Fields After Insert

If you want to clear the form after submission:

  1. Add another Process after the insert (or include it in the same one).

  2. Example:

:P1_FULL_NAME := NULL;
:P1_EMAIL := NULL;

This resets the form for the next entry.

Adding values from two controls into a table in Oracle APEX is quick and efficient using declarative form items and a simple PL/SQL process. This method provides flexibility to collect and store input from users in a secure and controlled way. Whether you're building a contact form, data logger, or simple data capture tool, this approach gives you the core structure to expand into more complex applications.

 

Adding Values from Two Textbox Items into a Database Table in Oracle APEX

Oracle APEX allows inserting values from multiple form fields into a database table using PL/SQL processes, dynamic actions, and form submissions. This tutorial covers different ways to insert values from two textbox items into a table.

 

Step 1: Create a Form with Two Textbox Items

  1. Open your Oracle APEX application.

  2. Click Create Page > Form > Form on a Table with Report.

  3. Choose the table where the values will be inserted (e.g., EMPLOYEE_DETAILS).

  4. In Page Designer, create two text fields: 

    • P1_EMP_NAME (for Employee Name)

    • P1_EMP_EMAIL (for Employee Email)

  5. Add a Submit or Save button (P1_SAVE_BUTTON).

 

Step 2: Create a PL/SQL Process to Insert Data

  1. In Page Designer, go to the Processing section.

  2. Click Create Process, select PL/SQL Code, and enter the following:

BEGIN

    INSERT INTO employee_details (emp_name, emp_email)

    VALUES (:P1_EMP_NAME, :P1_EMP_EMAIL);


    COMMIT;

END;

  1. Set Execution Point to After Submit and When Button Pressed to P1_SAVE_BUTTON.

  2. Click Save and Run the page.

When users enter values in the textboxes and click Save, the data will be inserted into EMPLOYEE_DETAILS.

 

Step 3: Confirm Success with a Message

To show a success message after inserting the record:

  1. Open Page Designer, go to Messages, and add the following code inside the PL/SQL process:

apex_util.set_session_state('P1_SUCCESS_MSG', 'Record successfully added!');

  1. Create a new static region and add a Display Item (P1_SUCCESS_MSG) to show the message.

  2. Set Source to PL/SQL Expression:

:P1_SUCCESS_MSG

Now, after submitting, users will see a confirmation message.

 

Alternative: Insert Data Using AJAX (Without Page Refresh)

If you want to insert data without refreshing the page, use AJAX and Dynamic Actions.

Step 1: Create an AJAX PL/SQL Process

  1. Go to Shared Components > Application Processes.

  2. Click Create Process, name it INSERT_EMPLOYEE_AJAX, and enter the following PL/SQL:

BEGIN

    INSERT INTO employee_details (emp_name, emp_email)

    VALUES (:P1_EMP_NAME, :P1_EMP_EMAIL);


    COMMIT;

END;

  1. Set Process Type to Ajax Callback.

Step 2: Create a Dynamic Action

  1. In Page Designer, select the Save Button (P1_SAVE_BUTTON).

  2. Click Create Dynamic Action and set:

    • Event: Click

    • Action: Execute JavaScript

  3. Add this JavaScript code:

apex.server.process("INSERT_EMPLOYEE_AJAX", {

    pageItems: "#P1_EMP_NAME, #P1_EMP_EMAIL"

}, {

    success: function(data) {

        alert("Record successfully added!");

        apex.item("P1_EMP_NAME").setValue("");

        apex.item("P1_EMP_EMAIL").setValue("");

    },

    error: function(request) {

        alert("Error inserting record.");

    }

});

This method inserts values without refreshing the page and clears the textboxes after insertion.

 

Best Practices

  • Validate Inputs: Ensure users enter valid data before inserting records.

  • Use Dynamic Actions for Better User Experience: Avoid full-page reloads by using AJAX.

  • Confirm Successful Insertions: Show success messages after inserting values.

  • Use Form Submissions for Simple Implementations: When AJAX is not required, a simple PL/SQL process on Submit works well.

 

Oracle APEX provides multiple ways to insert values from two textboxes into a table. You can use PL/SQL processes for form submissions or AJAX for real-time updates without refreshing the page. The best approach depends on your application's requirements.


EXAMPLE:

Assuming a page with 2 textboxes and a button. We want to take the two values from the controls and add them into the database as a new entry.

A screenshot of a computer

AI-generated content may be incorrect.


Step 1 – Add two textboxes to page 

A screenshot of a computer

Description automatically generated


Step 2 – Add a button with a Dynamic Action with two true branches

A screenshot of a computer

Description automatically generated

Step 3 – Set the following code in the first true branch

A screenshot of a computer program

AI-generated content may be incorrect.

The code is as follows:

BEGIN

INSERT INTO TEST_A (VALUEA1, VALUEA2)

VALUES (:P49_TESTA_VALUEA1_VALUE,:P49_TESTA_VALUEA2_VALUE);

 END;


Step 4 – add a report at the bottom of the page with the following settings.

A green and white sign

Description automatically generated


A screenshot of a computer

Description automatically generated


Step 5 – In the button’s second True branch set as follows.

A screenshot of a computer

Description automatically generated


You should now see something like this

A screenshot of a computer

Description automatically generated  A screenshot of a computer

Description automatically generated

Conclusion
Inserting values from two controls into a table in Oracle APEX is a foundational task that reinforces the platform’s strength in rapid form development. With a few clicks or lines of code, developers can bind input fields to database columns and ensure accurate data capture. This process supports flexible UI design while maintaining data consistency, forming the backbone of many real-world APEX applications.

 

No comments:

Post a Comment

How Do I Make a Faceted Search Map Page in Oracle APEX

Combining faceted search with a map region in Oracle APEX enables users to filter data visually and spatially at the same time. This design ...