1

I am trying to write a following PL/SQL function body for a dynamic action

The purpose of dynamic action is to set value for text area based on input parameters. Way I am trying to do it, is that setting the value into variable for different options

declare

P_NOTE varchar(100);  -- derive value
P_WEBSERVER varchar(100);  -- derive name

begin

-- for getting the P_NOTE value
select distinct note into P_NOTE  from port_mapping where PLATFORM = :P3_PLATFORM and VERSION = :P3_VERSION;

-- for getting web server value
select CONCAT(P_NOTE,CONCAT('https-',:P3_CLIENT)) into P_WEBSERVER from dual order by 1;

if (:P3_PLATFORM = 'Apache') then
    return P_WEBSERVER;
end if;

end;

However I am getting error

ORA-06550: line 15, column 5: PLS-00372: In a procedure, RETURN statement cannot contain an expression ORA-06550: line 15, column 5: PL/SQL: Statement ignored

  1. declare
  2. P_NOTE varchar(100);
  3. P_WEBSERVER varchar(100);

I am not sure what I am missing.

1
  • I suspect you'd get this error if your dynamic action's "Type" is not set to PL/SQL Function Body which is what I think you want. Side note: your code is missing a RETURN in the case when :P3_PLATFORM != 'Apache'. Aug 22, 2013 at 2:26

2 Answers 2

3

(Since you did not post any apex version this explanation deals with version 4.2)


If this -is- a dynamic action and the code you posted is in a true action of type 'Execute PL/SQL Code' then you can not use RETURN. The plsql block is not a function body (close, Mr Kemp!).
If you want to return values from the session state to page items then you need to use the "Page Items to Return" item of the true action. Execute plsql code in dynamic action This will put the session state of the defined page items into the value of the item on the page. This means that you can not use any variable to just put stuff in to be able to return it to the page, but you need to use an actual page item (after all, these are bind variables).
To clarify further, you would not write :

return P_WEBSERVER;

But you'd have to use a page item, say P3_WEBSERVER, and you'll need to create one if it doesn't exist of course:

:P3_WEBSERVER := p_webserver;

Of course you'd need to make sure that the correct value will be in there as you can not shortcircuit as you did in your code sample (p_webserver will usually hold a value even if the platform is not 'Apache') eg:

if (:P3_PLATFORM = 'Apache') then
   :P3_WEBSERVER := P_WEBSERVER;
else
   :P3_WEBSERVER := NULL;
end if;
4
  • I am using Apex 4.2. I am using PL/SQL Function Block, and not the PL/SQL expression Aug 22, 2013 at 17:09
  • Okay you lost me. Are you using a dynamic action or not? Is this a page process somewhere? Where is this code defined?
    – Tom
    Aug 22, 2013 at 18:25
  • I'm tackling with the same thing and similar to above code is in a process! however the :P3_WEBSERVER := P_WEBSERVER; line doesn't change the value of the text field! even if I assign a static value!
    – Saba Ahang
    Mar 4, 2015 at 13:59
  • @SabaAhang Did you set P3_WEBSERVER as an item to be returned?
    – Tom
    Apr 16, 2015 at 8:56
2

Just read error message:

line 15, column 5

So, trouble caused by this line:

return P_WEBSERVER;

return not allowed in PL/SQL blocks, use output parameter to return a value.

Read Tom's answer to find out how to do that.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.