Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Setting the value of a form field from a Query

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?

like image 738
Roy Avatar asked Dec 29 '22 00:12

Roy


2 Answers

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;
like image 100
Roy Avatar answered Jan 10 '23 19:01

Roy


You can use the SQL query in a PL/SQL block to assign it directly, e.g.

SELECT default_rate
INTO :myblock.rate
FROM app_defaults
WHERE row_key = 1;
like image 34
Jeffrey Kemp Avatar answered Jan 10 '23 20:01

Jeffrey Kemp