{"id":26,"date":"2008-11-18T10:12:51","date_gmt":"2008-11-18T10:12:51","guid":{"rendered":"https:\/\/www.spotonoracle.com\/?p=26"},"modified":"2016-05-10T10:13:47","modified_gmt":"2016-05-10T10:13:47","slug":"qualified-names","status":"publish","type":"post","link":"https:\/\/www.spotonoracle.com\/?p=26","title":{"rendered":"Qualified names"},"content":{"rendered":"<p>Have you ever looked at a big long package\/procedure and wondered what the scope of a variable might be in this web of nested named and unnamed PL\/SQL blocks? I\u2019m sure all of you have.<br \/>\nThere are a few naming convention proposals out there that suggest using prefixes like \u201cl_\u201d for local, \u201cg_\u201d for global variables, etc which is some kind of Systems Hungarian notation (I&#8217;m not convinced of the usefulness of System Hungarian whereas I can see some benefit of App Hungarian if properly applied on the variable scope &#8211; <a href=\"http:\/\/www.joelonsoftware.com\/articles\/Wrong.html\">read more about it at Joel&#8217;s<\/a>).<br \/>\nThe problem rises when there are multiple nested blocks, what\u2019s now the scope of this \u201cl_\u201d prefixed variable again? You simply don\u2019t know until you back track it to the declaration of that variable.<br \/>\nThat\u2019s where qualified names come in pretty handy, let\u2019s examine:<\/p>\n<pre class=\"brush: sql; collapse: false; title: ; wrap-lines: false; notranslate\" title=\"\">\r\ncreate or replace package pck\r\nas\r\n  procedure p1 (\r\n     text in varchar2\r\n  );\r\nend pck;\r\n\/\r\n\r\ncreate or replace package body pck\r\nas\r\n  text varchar2(10);\r\n \r\n  procedure p1 (\r\n     text in varchar2\r\n  )\r\n  is\r\n  begin\r\n    pck.text := p1.text;\r\n  end p1;\r\nend pck;\r\n\/\r\n<\/pre>\n<p>Note that in procedure P1 we use qualifiers for the variable and parameter TEXT. Even though they have the same name, the scope is very clear. We could even qualify the parameter with the package name which would make it a bit long, e.g. &#8220;<strong>pck.text := pck.p1.text;<\/strong>&#8221;<br \/>\nIsn\u2019t this beautiful? Absolutely, but as soon as we use long package, procedure and variable names it can make the code somewhat cumbersome to read as you end up with very long expressions. In my opinion I think the benefits of qualified names far outweigh the disadvantages of having a bit longer code lines \u2013 you can look at one (maybe big) line of code and you have all the information, no need for scrolling up to the declaration to find out the scope.<\/p>\n","protected":false},"excerpt":{"rendered":"<p>Have you ever looked at a big long package\/procedure and wondered what the scope of a variable might be in this web of nested named and unnamed PL\/SQL blocks? I\u2019m sure all of you have. There are a few naming convention proposals out there that suggest using prefixes like \u201cl_\u201d for local, \u201cg_\u201d for global [&hellip;]<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4],"tags":[],"class_list":["post-26","post","type-post","status-publish","format-standard","hentry","category-plsql"],"_links":{"self":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts\/26","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=26"}],"version-history":[{"count":1,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions"}],"predecessor-version":[{"id":27,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=\/wp\/v2\/posts\/26\/revisions\/27"}],"wp:attachment":[{"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=26"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=26"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.spotonoracle.com\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=26"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}