Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use json_transform to remove an array element at an unknown index?

bsamuelOct 15 2021

In Oracle 21c how would one go about removing an array element at an unknown index using JSON_TRANSFORM? The following works fine in Apex as the item substitution does its job when using the comparison (@.name == "&PRD_NAME.") however it doesn't work if moving it into a database package as you can't build the comparison, eg (@.name == "' || p_prd_name || '") and the "passing" option is invalid in the "remove" clause.

update orders
   set order_attr = json_transform ( order_attr
                                   , remove '$.products[*]?(@.name == "&PRD_NAME.")' )
 where json_exists(order_attr, '$.products[*]?(@.name == $s)' passing :PRD_NAME as "s");

In the example many orders may have the product in question so this update needs to work on multiple rows.
Thanks!

This post has been answered by User_H3J7U on Oct 15 2021
Jump to Answer

Comments

Processing

Post Details

Added on Oct 15 2021
2 comments
1,911 views