{"id":73285,"date":"2012-09-11T16:01:54","date_gmt":"2012-09-11T16:01:54","guid":{"rendered":"https:\/\/www.red-gate.com\/simple-talk\/uncategorized\/plsql-exceptions-propagation-during-variable-declaration\/"},"modified":"2021-07-14T13:07:51","modified_gmt":"2021-07-14T13:07:51","slug":"plsql-exceptions-propagation-during-variable-declaration","status":"publish","type":"post","link":"https:\/\/www.red-gate.com\/simple-talk\/databases\/oracle-databases\/plsql-exceptions-propagation-during-variable-declaration\/","title":{"rendered":"PL\/SQL Exceptions Propagation during Variable Declaration"},"content":{"rendered":"<p>It&#8217;s always good to know how any language handles and propagates exceptions, Oracle PL\/SQL being no different. They&#8217;re plenty of examples online about raising and handling exceptions on the web, but one thing you may not have realized is how PL\/SQL propagates exceptions that occur in the variable declaration section of a procedure.<\/p>\n<p>In the first example I created a procedure that has a variable, l_var, which can handle one character. As expected, when I assign more then one character an exception is raised and is propagated to the EXCEPTION block of the procedure.<\/p>\n<pre>\r\nSQL> CREATE OR REPLACE PROCEDURE sp_test(p_var in varchar2)\r\n  2  AS\r\n  3    l_var VARCHAR2(1);\r\n  4  BEGIN\r\n  5    dbms_output.put_line('***START***');\r\n  6    l_var := 'abc';\r\n  7  exception\r\n  8    WHEN others THEN\r\n  9      dbms_output.put_line('***Exception***');\r\n 10      raise;\r\n 11  END sp_test;\r\n 12  \/\r\n \r\nProcedure created.\r\n \r\nSQL> exec sp_test(p_var => 'abc');\r\n***START***\r\n***Exception***\r\nBEGIN sp_test(p_var => 'abc'); END;\r\n \r\n*\r\nERROR at line 1:\r\nORA-06502: PL\/SQL: numeric or value error: character string buffer too small\r\nORA-06512: at \"ODTUG.SP_TEST\", line 10\r\nORA-06512: at line 1\r\n<\/pre>\n<p>Continue reading on <a href=\"http:\/\/www.talkapex.com\/2012\/09\/plsql-exceptions-propagation-during.html\" title=\"Martin Giffy D'Souza blog\" target=\"_blank\">my blog<\/a> for the next example&#8230;<\/p>\n","protected":false},"excerpt":{"rendered":"<p>It&#8217;s always good to know how any language handles and propagates exceptions, Oracle PL\/SQL being no different. They&#8217;re plenty of examples online about raising and handling exceptions on the web, but one thing you may not have realized is how PL\/SQL propagates exceptions that occur in the variable declaration section of a procedure. In the first example I created a&hellip;<\/p>\n","protected":false},"author":316179,"featured_media":0,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[143533],"tags":[],"coauthors":[],"class_list":["post-73285","post","type-post","status-publish","format-standard","hentry","category-oracle-databases"],"acf":[],"_links":{"self":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73285","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/users\/316179"}],"replies":[{"embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/comments?post=73285"}],"version-history":[{"count":1,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73285\/revisions"}],"predecessor-version":[{"id":91745,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/posts\/73285\/revisions\/91745"}],"wp:attachment":[{"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/media?parent=73285"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/categories?post=73285"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/tags?post=73285"},{"taxonomy":"author","embeddable":true,"href":"https:\/\/www.red-gate.com\/simple-talk\/wp-json\/wp\/v2\/coauthors?post=73285"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}