When working with Oracle Forms, developers often use Record Groups to manage lists of values (LOVs), populate dropdowns, or store query results temporarily. A Record Group is essentially an in-memory data structure that holds rows and columns, similar to a table. To fill a Record Group with data, Oracle Forms provides the POPULATE_GROUP built-in. This tutorial explains what POPULATE_GROUP is, how it works, and how you can use it to populate Record Groups dynamically in your applications.
What is POPULATE_GROUP?
The POPULATE_GROUP built-in is used to fill an existing Record Group with data from a query you have defined. Unlike POPULATE_GROUP_WITH_QUERY, which creates a new query-based group, POPULATE_GROUP expects that the Record Group is already created (usually at design time or dynamically using CREATE_GROUP).
This built-in is particularly useful when:
- You want to refresh a Record Group with the latest data.
- You need to use the same Record Group structure multiple times with updated rows.
- You want to load query results into a Record Group and use it in a List of Values (LOV).
Syntax of POPULATE_GROUP
The basic syntax is:
POPULATE_GROUP(group_id);
- group_id: The ID of the Record Group you want to populate. This ID can be retrieved using the
FIND_GROUPfunction.
The built-in returns a status code:
- 0 → Success
- 1 → Failure (for example, if the Record Group does not exist or the query fails)
Steps to Use POPULATE_GROUP
Here’s the step-by-step approach to using POPULATE_GROUP in Oracle Forms:
- Create a Record Group
- Either at design time using the Record Group object in Forms Builder.
- Or dynamically using
CREATE_GROUP.
- Define a Query for the Record Group
- Assign a SQL query that fetches the data you want.
- The query should match the structure (columns) of the Record Group.
- Find the Record Group at Runtime
- Use the
FIND_GROUPfunction to get the Record Group ID.
- Use the
- Call POPULATE_GROUP
- Use
POPULATE_GROUPto fill the Record Group with the query result.
- Use
- Check for Errors
- Handle cases where the population fails, for example due to invalid SQL or missing group.
Example: Populating a Record Group
Suppose you have a Record Group named RG_DEPARTMENTS, created at design time with the following query:
SELECT department_id, department_name FROM departments;
You can populate it at runtime using:
DECLARE
rg_id RecordGroup;
ret NUMBER;
BEGIN
rg_id := FIND_GROUP('RG_DEPARTMENTS');
ret := POPULATE_GROUP(rg_id);
IF ret = 0 THEN
MESSAGE('Record Group populated successfully.');
ELSE
MESSAGE('Error while populating Record Group.');
END IF;
SYNCHRONIZE;
END;
This will refresh the Record Group with the latest department data.
Using POPULATE_GROUP with LOVs
A common use case is to populate a Record Group that is attached to a List of Values (LOV). For example:
- Create a Record Group RG_EMPLOYEES with query:
SELECT employee_id, last_name FROM employees;
- Create an LOV LOV_EMPLOYEES based on this Record Group.
- Populate the Record Group at runtime:
DECLARE
rg_id RecordGroup;
ret NUMBER;
BEGIN
rg_id := FIND_GROUP('RG_EMPLOYEES');
ret := POPULATE_GROUP(rg_id);
IF ret = 0 THEN
SHOW_LOV('LOV_EMPLOYEES');
ELSE
MESSAGE('Could not populate employee LOV.');
SYNCHRONIZE;
END IF;
END;
This ensures the LOV always shows the most up-to-date employee data.
Handling Dynamic Queries
Sometimes you may want to run different queries for the same Record Group. In that case, you can use SET_GROUP_QUERY first, and then call POPULATE_GROUP:
DECLARE
rg_id RecordGroup;
ret NUMBER;
BEGIN
rg_id := FIND_GROUP('RG_DYNAMIC');
SET_GROUP_QUERY(rg_id, 'SELECT job_id, job_title FROM jobs');
ret := POPULATE_GROUP(rg_id);
IF ret = 0 THEN
MESSAGE('Dynamic query data loaded.');
ELSE
MESSAGE('Error loading data dynamically.');
END IF;
SYNCHRONIZE;
END;
This approach is helpful when you want to reuse one Record Group with different SQL queries.
Best Practices for Using POPULATE_GROUP
- Always check the return value
- Never assume the population succeeded. Handle errors gracefully.
- Keep queries optimized
- Since POPULATE_GROUP executes the query in real time, a poorly written query will slow down your form.
- Use with LOVs for dynamic lists
- Instead of hardcoding LOV data, always use POPULATE_GROUP to fetch the latest values from the database.
- Reuse Record Groups where possible
- Instead of creating multiple groups for similar structures, use
SET_GROUP_QUERYwith POPULATE_GROUP.
- Instead of creating multiple groups for similar structures, use
- Avoid very large result sets
- Record Groups are stored in memory, so loading too many rows can impact performance.
Common Errors and Troubleshooting
- ORA-04043: object does not exist → The Record Group name provided to
FIND_GROUPis incorrect. - POPULATE_GROUP returns 1 → Query mismatch or invalid group structure.
- LOV not displaying values → Ensure the Record Group is populated before calling
SHOW_LOV.
Conclusion
The POPULATE_GROUP built-in in Oracle Forms is a powerful tool for filling Record Groups with data dynamically. It is particularly valuable when working with LOVs, dropdowns, or whenever you need temporary in-memory datasets. By combining FIND_GROUP, SET_GROUP_QUERY, and POPULATE_GROUP, you can create flexible and dynamic user interfaces in your forms.
Following best practices such as checking return values, optimizing queries, and avoiding unnecessary groups ensures that your forms remain efficient and user-friendly.

