Setting the value of a form field from a Query

Roy picture Roy · Mar 3, 2011 · Viewed 25.9k times · Source

I have a form field where one of the values has a default value defined in a an application settings table. The user would see the default value upon display of the create form, but could change it to another value if they wanted prior to saving the new row.

I don't see any way in the field defaults to specify that the default value is the result of an SQL query (e.g. select default_rate from app_defaults where row_key = 1).

Surely this has to be possible, but how?

Answer

Roy picture Roy · Mar 9, 2011

As posted to Jeffrey above, final solution can be done completely within APEX but using the Default Value Type = PL/SQL Function Body on the page item.

DECLARE default_value number(9,2); 
BEGIN 
SELECT deflt_rate INTO default_value FROM app_defaults WHERE row_key = 1; 
RETURN default_value; 
END;