4 Replies Latest reply on Mar 27, 2014 2:06 PM by Denes Kubicek

    Set Default value to Textbox

    Manas M

      I need to set a default value to one of my textbox field of a form. The default value should be the latest record from the database.(i.e the latest column value from the database)

        • 1. Re: Set Default value to Textbox
          Denes Kubicek

          In the default value of the text box choose PL/SQL Function Body and use code similar to this:

           

          DECLARE

             v_text_box_default   VARCHAR2 (4000);

          BEGIN

             SELECT text_box_table.text_box_column

               INTO v_text_box_default

               FROM text_box_table,

                    (SELECT MAX (ID) max_id

                       FROM text_box_table) text_box_table_max

              WHERE text_box_table.ID = text_box_table_max.max_id;

           

             RETURN v_text_box_default;

          EXCEPTION

             WHEN OTHERS

             THEN

                RETURN NULL;

          END;

           

          It is better to create a computation since it is visible on the page and make it conditional to fire only if the text box is empty.

           

          Denes Kubicek

           

          -------------------------------------------------------------------

           

          -------------------------------------------------------------------

          • 2. Re: Set Default value to Textbox
            Manas M

            Thanks Denes

            • 3. Re: Set Default value to Textbox
              fac586

              Denes Kubicek wrote:

               

                        (SELECT MAX (ID) max_id

                           FROM text_box_table) text_box_table_max

              Assuming the ID value is sourced from a sequence, this will not identify the last created row in all circumstances. It is necessary to use a timestamp column on the table to do so.

              EXCEPTION

                 WHEN OTHERS

                 THEN

                    RETURN NULL;

              Surely not!

              • 4. Re: Set Default value to Textbox
                Denes Kubicek

                Hm,

                 

                I I use no caching the query should return the last row. Timestmap is for sure better. Usually you have two minutes to answer questions like that. Personally, I wouldn't do this that way - this is just quick and dirty. What does "Surely not!" means?

                 

                Denes Kubicek

                 

                -------------------------------------------------------------------

                -------------------------------------------------------------------