This is a continuation from the previous section. Further proceeding we have the following: begin The above is the part of the main program. In fact, the execution starts at the above "begin" and then calls the procedure "add_profit" with two parameters. From this statement, the execution jumps to the stored procedure "add_profit" and, well, executes it. Once it completes the execution of "add_profit," the control returns back to the main program and executes the next statement. In fact, the control jumps from main program to sub program quite a number of times, depending upon necessity. Finally, we called the "print_profits" and "print_total_profit" without any parameters (as they don't require them), which prints all that we have added to the associative array. And thus we complete our discussion on the best approach to work with associative arrays. Extending the program a bit Can we still improve the program with a few more procedures? To which my answer is, Why not? You can still make it more modular and flexible. In the above program, I didn't give any approach for deleting any element within the associative array. Now, let us extend the above with an additional procedure as follows: procedure delete_profit(year number) as Even though the above procedure is simple, it really gives you a good opportunity to delete the elements within the associative array in a very simple fashion. Once you add the above procedure to the previous program (within the "declaration" section), modify the body of your program with the following code: begin print_profits; dbms_output.put_line('-----------------'); I added a few more statements to the already existing statements, just to demonstrate the functionality of the new procedure we added to the program. It simply displays all the elements added first and then displays all elements after deletion, separated by a line.
blog comments powered by Disqus |