Wednesday, August 15, 2018

Replace deprecated apex_util.string_to_table (APEX 5.1/18.1)

Sometimes the Oracle APEX documentation announces some packages will become deprecated in a release. It's not that those packages are suddenly gone, but you should not use them anymore. Your code will run fine still, but in the future, APEX might take it out completely, so it's best to replace them with the new package.

One of those packages announced in Oracle APEX 5.1 that are deprecated, and which I used a lot, was apex_util.string_to_table.

For example, in APEX Office Print (AOP) we read the session state of page items and we have some code like this:

  l_string          varchar2(4000) := 'P1_X:P1_Y';
  l_page_items_arr  apex_application_global.vc_arr2;
  l_page_items_arr := apex_util.string_to_table(p_string => l_string, p_separator => ':');
  for i in 1..l_page_items_arr.count
  end loop;

As the function is deprecated and APEX is already on release 18.1, it's good to start replacing those calls. The new function you can use is apex_string.split.

The above code becomes then:
  l_string          varchar2(4000) := 'P1_X:P1_Y';
  l_page_items_arr  apex_t_varchar2;
  l_page_items_arr := apex_string.split(p_str => l_string, p_sep => ':');
  for i in 1..l_page_items_arr.count
  end loop;

Depending on your application, you might need to be careful. For example with AOP, we support customers with versions of Oracle APEX 5.0, 5.1 and 18.1. We can't really force customers to move to higher APEX versions, so the way we solve it is by using conditional compilation of our code. If we see you are on APEX 5.1 or above we will use apex_string.split if not, and you are still on an earlier version, we will use apex_util.string_to_table.

Here's an example of what the code with conditional compilation looks like:
  $if wwv_flow_api.c_current >= 20160824
    l_page_items_arr := apex_string.split(p_str=>l_string, p_sep=>':');
    l_page_items_arr := apex_util.string_to_table(p_string=>l_string, p_separator=>':');

Note the conditional compilation you also need to do on the variable if they are different, or you can choose to conditional compile on the entire function.

To conclude, I recommend with every new release of Oracle APEX to look for deprecated components and search for those and make notes to change those when needed.


Steve Norman said...

Thanks for this Dimitri - I just spotted that this function is deprecated in the 5.1 API Guide.

Is there a way to easily search for ALL deprecated features that are being used by an application? Or is it a case of checking documentation for deprecated functionality and manually trawling through the application for each deprecated API call?

Dimitri Gielis said...

Hi Steve,

In APEX if you could go to Application - Utilities and click the Upgrade Application link - it will show you things to upgrade.
This mostly works for APEX itself eg. Anychart to JET chart.

For the PL/SQL API you could write a query to check the meta-data for things that are deprecated.
I don't know a tool that does it for you. We (APEX R&D) have some plans in creating this, but that is not there yet today.

Hope that helps,

Angel Flores Torres said...

Hello what, about the return values, in some point maybe that functions returns a different type of values right ? ... What are your recommendations at that point

IB said...

Thanks your example helped me a lot

Tony said...

Is it possible to use the apex_string.split function without installing APEX? We cannot install APEX on a system, but would like to use the feature.