lui862
lui862

Reputation: 55

Oracle Apex- Branch to another page based on PL/SQL function body returning a URL

I am trying to perform page branch based on the the query from the table. The query it is running and returning something but the statement is only executing the else part which makes me think the value from the query is not being passed down to the evaluated variable in the statement. How best can I achieve this?

Declare
evaluated NUMBER;
SELECT COUNT(*) INTO evaluated FROM USER_EVALUATION join term using(term_id)
WHERE EVALUATION.USER_ID=:P1_ID 
    and term_id =:P1_TERM;

    IF evaluated > 1 THEN
        RETURN 'page_link1_here';

    ELSE
        RETURN 'page_link2_here';

    END IF;
END;

Upvotes: 0

Views: 1390

Answers (2)

Ian Ward
Ian Ward

Reputation: 98

Your PL/SQL block is missing the BEGIN keyword.

The best way of checking what the actual values of P1_ID and P1_TERM are when this block is running is to insert them into a table for testing. You'll likely see that their values are NULL because like Littlefoot suggests the values of the item on the page (within the DOM) are not what is used for when the PLSQL runs. The PLSQL is only interested in the items value that is saved in session state.

Saving to session state is done when the page is submitted but can be done with PLSQL piror to submitting the page using this procedure:

BEGIN

    APEX_UTIL.SET_SESSION_STATE('P1_ITEM', 'New Value');

END;

Upvotes: 1

Littlefoot
Littlefoot

Reputation: 142753

If ELSE part is always returned, then count(*) = 0 which means that either there are no rows there that satisfy conditions, or page item values aren't in session state. Doesn't matter you see them on the screen.

I'd suggest you to submit the page - that will put P1_ID and P1_TERM into session state, and then you'll see whether another link is being returned or not.

Upvotes: 1

Related Questions