Setting APEX select list default value based on parameter

Marcus Culver picture Marcus Culver · Nov 21, 2012 · Viewed 17.5k times · Source

I have an Apex page with a select list item populated from a SQL query that should default to the product of the item passed through from another page, however it always selects the first item in the list.

We need to set it so it selects the current category however I can't see where this setting is. The version of APEX is 3.2.

Answer

Jeffrey Kemp picture Jeffrey Kemp · Nov 22, 2012

Firstly, I suspect (correct me if I'm wrong) that your item is selecting the first item because the item is defined with Display Null Value set to No; internally, however, the item is probably NULL, but the list item cannot show it so it just shows the first list value. But I probably wouldn't change this setting.

To set the default value for a Select List item, set Default Value Type to PL/SQL Function Body, then enter your SQL query (that returns a single value) in the Default attribute for the item, with suitable PL/SQL around it, e.g.:

DECLARE
  v_value VARCHAR2(<your data max length>);
BEGIN
  SELECT <yourcolumn>
  INTO v_value
  FROM <yourquery>;
  RETURN v_value;
END;