{"id":546,"date":"2011-12-14T10:09:05","date_gmt":"2011-12-14T10:09:05","guid":{"rendered":"http:\/\/bar-solutions.com\/weblog\/?p=546"},"modified":"2011-12-14T10:09:05","modified_gmt":"2011-12-14T09:09:05","slug":"","status":"publish","type":"post","link":"https:\/\/blog.bar-solutions.com\/?p=546","title":{"rendered":"Timing in PL\/SQL"},"content":{"rendered":"<p align=\"left\">In my current project I wanted to add some timing to the logging the code already does. So I started my search for a good timing package. My first idea was to download <a href=\"http:\/\/www.toadworld.com\/Freeware\/PLVisionFreeware\/tabid\/687\/Default.aspx\" title=\"Toad World &gt; Freeware &gt; PL\/Vision Freeware\" rel=\"nofollow\" target=\"_blank\">PL\/Vision<\/a> and use the timer that is in there. Installing this was not as simple as I hoped it to be. The PLVTMR package relies on a couple of other packages, which in turn rely on&#8230; Not what I wanted in my current project. I was actually looking for a stand alone package which I could use. So, my search continues and brings me to <a title=\"oracle-developer.net\" href=\"http:\/\/www.oracle-developer.net\/\" rel=\"nofollow\" target=\"_blank\">oracle-developer.net<\/a> where I found the <a title=\"timer.sql\" href=\"http:\/\/www.oracle-developer.net\/content\/utilities\/timer.sql\" rel=\"nofollow\" target=\"_blank\">timer.sql<\/a> script. It was good, but not good enough.<\/p>\n<div align=\"left\">\n<p><!--more--><\/p>\n<\/div>\n<p align=\"left\">This script was built for usage in demos and to check if different implementations differ in speed. Therefore the timer is just written to output using a procedure. I need a function to return the value of the timer so I can use the resulting value in a log message.<\/p>\n<p align=\"left\">I decided to take this package as a starting point and adjust it to fit my needs. That&#8217;s why I added a function to retrieve the value which would otherwise be sent to the DBMS_OUTPUT buffer. It was actually just a copy of the show procedure with just a few adjustments.<\/p>\n<p align=\"left\">If, like me, you want to achieve <a title=\"QuestTV - Steven Feuerstein&#39;s Practical Best PL\/SQL - SPODify your code - aim for a Single Point of Definition\" href=\"http:\/\/www.quest.com\/tv\/959824230001\/Steven-Feuersteins-Practical-Best-PLSQL---SPODify-your-code---aim-for-a-Single-Point-of-Definition\/Video\/\" rel=\"nofollow\" target=\"_blank\">SPOD<\/a> (Single Point Of Definition), then just copying bits of code just doesn&#8217;t feel right. Just looking at the code revealed that I declared the same type twice. This should be done in the declaration section of the package, so I could use it in multiple programs. I also noticed that retrieving the current timing value was done twice in exactly the same manner. This also calls for some refactoring. So I created a function that returns the timing values in a record. Hey, I can use the type I just declared globally to the package. Another great advantage of refactoring.<\/p>\n<p align=\"left\">After having created the function to retrieve the timing value I started using it. While using it, I found out that I actually wanted to run multiple timers at the same time. The current package only provides a single timer so I decided to add support for multiple timers. Doing so seems easy enough by using an Associative Array. But index it by a numeric value doesn&#8217;t seem like a good idea. Since <a title=\"Oracle\" href=\"http:\/\/www.oracle.com\/\" rel=\"nofollow\" target=\"_blank\">Oracle<\/a> 9i Release 2 we can also index by VARCHAR2 which is probably a better idea than using a numeric index. Chances of using the same name for concurrently running timers are smaller than the chance of using the same number twice.<\/p>\n<p align=\"left\">I don&#8217;t think the code is completely done and there are certainly some pieces that can use improvement, but it works for me. If you come up with an improved version, don&#8217;t hesitate to let me (and Adrian Billington) know.<\/p>\n<p align=\"left\">The code for the (modified) timer package can be found <a title=\"timer.sql\" href=\"http:\/\/bar-solutions.com\/weblog\/wp-content\/timer\/timer.sql\" rel=\"nofollow\" target=\"_blank\">here<\/a>.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>In my current project I wanted to add some timing to the logging the code already does. So I started my search for a good timing package. My first idea was to download PL\/Vision and use the timer that is in there. Installing this was not as simple as I hoped it to be. The [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[2,5,4],"tags":[],"class_list":["post-546","post","type-post","status-publish","format-standard","hentry","category-oracle","category-plsql","category-tools"],"_links":{"self":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/546","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=546"}],"version-history":[{"count":0,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=\/wp\/v2\/posts\/546\/revisions"}],"wp:attachment":[{"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=546"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=546"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/blog.bar-solutions.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=546"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}