Last active
February 8, 2023 19:22
-
-
Save jon-dixon/f9b9c1750cbf2a4d118e072104bdd778 to your computer and use it in GitHub Desktop.
Working with Lists APEX_STRING.PLIST
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
DECLARE | |
CURSOR cr_tasks IS | |
SELECT task_id | |
, task_owner | |
FROM cndemo_tasks; | |
lt_owner_task_count apex_t_varchar2; | |
l_task_count NUMBER; | |
BEGIN | |
-- Loop through all tasks. | |
FOR task_rec IN cr_tasks LOOP | |
BEGIN | |
-- Attempt to get the task count for the owner of the current task in the loop. | |
l_task_count := apex_string.plist_get | |
(p_table => lt_owner_task_count, | |
p_key => task_rec.task_owner); | |
-- If we don't get a NO_DATA_FOUND exception, then we can increment the count. | |
-- apex_string.plist_put looks up the value in p_key and updates the associated value using p_value | |
apex_string.plist_put | |
(p_table => lt_owner_task_count, | |
p_key => task_rec.task_owner, | |
p_value => l_task_count + 1); | |
EXCEPTION WHEN NO_DATA_FOUND THEN | |
-- Create an initial record in the array for the new Task Owner. | |
apex_string.plist_put | |
(p_table => lt_owner_task_count, | |
p_key => task_rec.task_owner, | |
p_value => 1); | |
END; | |
END LOOP; | |
apex_string.plist_push | |
(p_table => lt_owner_task_count, | |
p_key => 'CNDEMO', | |
p_value => 0); | |
apex_string.plist_put | |
(p_table => lt_owner_task_count, | |
p_key => 'CNDEMO', | |
p_value => 99); | |
-- Show the Owners and Task Counts. | |
dbms_output.put_line('Before Delete: ' || apex_string.join(lt_owner_task_count,':')); | |
-- Delete the record for CNDEMO | |
apex_string.plist_delete(lt_owner_task_count, 'CNDEMO'); | |
-- Show the Owners and Task Counts again. | |
dbms_output.put_line('After Delete : ' ||apex_string.join(lt_owner_task_count,':')); | |
END; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment