{"id":1590,"date":"2017-12-01T15:35:47","date_gmt":"2017-12-01T08:35:47","guid":{"rendered":"https:\/\/oracletutorial.com\/?page_id=1590"},"modified":"2025-05-30T01:44:27","modified_gmt":"2025-05-30T08:44:27","slug":"plsql-package","status":"publish","type":"page","link":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/","title":{"rendered":"PL\/SQL Package"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: in this tutorial, you&#8217;ll learn about the PL\/SQL package and the advantages of using the packages in application development.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='what-is-a-plsql-package'>What is a PL\/SQL package <a href=\"#what-is-a-plsql-package\" class=\"anchor\" id=\"what-is-a-plsql-package\" title=\"Anchor for What is a PL\/SQL package\">#<\/a><\/h2>\n\n\n\n<p>In PL\/SQL, a package is a schema object that contains definitions for a group of related functionalities. A package includes <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-variables\/\">variables<\/a>, <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-constants\/\">constants<\/a>, <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-cursor\/\">cursors<\/a>, <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-exception\/\">exceptions<\/a>, <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-procedure\/\">procedures<\/a>, <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-function\/\">functions<\/a>, and subprograms. It is compiled and stored in the Oracle Database.<\/p>\n\n\n\n<p>Typically, a package has a <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package-specification\/\">specification<\/a> and a <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package-body\/\">body<\/a>. A package specification is mandatory while the package body can be required or optional, depending on the package specification.<\/p>\n\n\n\n<p>The following picture illustrates PL\/SQL packages:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"851\" height=\"273\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package.jpg\" alt=\"pl\/sql package\" class=\"wp-image-1593\" title=\"pl\/sql package\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package.jpg 851w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package-300x96.jpg 300w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package-768x246.jpg 768w\" sizes=\"auto, (max-width: 851px) 100vw, 851px\" \/><\/figure>\n\n\n\n<h3 class=\"wp-block-heading\" id='package-specification'>Package specification <a href=\"#package-specification\" class=\"anchor\" id=\"package-specification\" title=\"Anchor for Package specification\">#<\/a><\/h3>\n\n\n\n<p>The package specification declares the public objects that are accessible from outside the package.<\/p>\n\n\n\n<p>If a package specification whose public objects include cursors and subprograms, then it must have a body that defines queries for the cursors and code for the subprograms.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='package-body'>Package body <a href=\"#package-body\" class=\"anchor\" id=\"package-body\" title=\"Anchor for Package body\">#<\/a><\/h3>\n\n\n\n<p>A <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package-body\/\">package body<\/a> contains the implementation of the cursors or subprograms declared in the package specification. In the package body, you can declare or define private variables, cursors, etc., used only by the package body itself.<\/p>\n\n\n\n<p>A package body can have an initialization part whose statements initialize variables or perform other one-time setups for the whole package.<\/p>\n\n\n\n<p>A package body can also have an exception-handling part used to handle <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-exception\/\">exceptions<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='why-use-plsql-packages'>Why use PL\/SQL packages <a href=\"#why-use-plsql-packages\" class=\"anchor\" id=\"why-use-plsql-packages\" title=\"Anchor for Why use PL\/SQL packages\">#<\/a><\/h2>\n\n\n\n<p>The package is a powerful feature of PL\/SQL that you should use it in any project. The following are the advantages of the package:<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='make-code-more-modular'>Make code more modular <a href=\"#make-code-more-modular\" class=\"anchor\" id=\"make-code-more-modular\" title=\"Anchor for Make code more modular\">#<\/a><\/h3>\n\n\n\n<p>Packages allow you to encapsulate logically related types, variables, constants, subprograms, cursors, and exceptions in named PL\/SQL modules. By doing this, you make each package more reusable, manageable, readable, and reliable.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='hide-implementation-details'>Hide implementation details <a href=\"#hide-implementation-details\" class=\"anchor\" id=\"hide-implementation-details\" title=\"Anchor for Hide implementation details\">#<\/a><\/h3>\n\n\n\n<p>Packages allow you to expose the functionality via their specifications and hide the detailed implementation in the package body.<\/p>\n\n\n\n<p>It means that you can enhance the code in the body of the package without affecting other dependent packages or applications.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='improve-application-performance'>Improve application performance <a href=\"#improve-application-performance\" class=\"anchor\" id=\"improve-application-performance\" title=\"Anchor for Improve application performance\">#<\/a><\/h3>\n\n\n\n<p>Oracle loads the package into memory the first time you invoke a package subprogram. The subsequent calls of other subprograms in the same package do not require disk I\/O. This mechanism helps improve performance.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='minimize-unnecessary-recompiling-code'>Minimize unnecessary recompiling code <a href=\"#minimize-unnecessary-recompiling-code\" class=\"anchor\" id=\"minimize-unnecessary-recompiling-code\" title=\"Anchor for Minimize unnecessary recompiling code\">#<\/a><\/h3>\n\n\n\n<p>Packages help avoid the unnecessary recompiling process. For instance, if you change the body of a package function, Oracle does not recompile the subprograms that use the function, because the subprograms are only dependent on the package specification, not the package body.<\/p>\n\n\n\n<h3 class=\"wp-block-heading\" id='manage-authorization-easily'>Manage authorization easily <a href=\"#manage-authorization-easily\" class=\"anchor\" id=\"manage-authorization-easily\" title=\"Anchor for Manage authorization easily\">#<\/a><\/h3>\n\n\n\n<p>By encapsulating objects in a package, you grant roles on the package, instead of granting roles to each object in the package.<\/p>\n\n\n\n<p>PL\/SQL package concept is simple but powerful. They allow you to encapsulate the code and make your application easier to develop and maintain.<\/p>\n<div class=\"helpful-block-content\" data-title=\"\">\n\t<header>\n\t\t<div class=\"wth-question\">Was this tutorial helpful?<\/div>\n\t\t<div class=\"wth-thumbs\">\n\t\t\t<button\n\t\t\t\tdata-post=\"1590\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/\"\n\t\t\t\tdata-post-title=\"PL\/SQL Package\"\n\t\t\t\tdata-response=\"1\"\n\t\t\t\tclass=\"wth-btn-rounded wth-yes-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t\tclass=\"feather feather-thumbs-up block w-full h-full\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M14 9V5a3 3 0 0 0-3-3l-4 9v11h11.28a2 2 0 0 0 2-1.7l1.38-9a2 2 0 0 0-2-2.3zM7 22H4a2 2 0 0 1-2-2v-7a2 2 0 0 1 2-2h3\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> Yes <\/span>\n\t\t\t<\/button>\n\n\t\t\t<button\n\t\t\t\tdata-response=\"0\"\n\t\t\t\tdata-post=\"1590\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/\"\n\t\t\t\tdata-post-title=\"PL\/SQL Package\"\n\t\t\t\tclass=\"wth-btn-rounded wth-no-btn\"\n\t\t\t>\n\t\t\t\t<svg\n\t\t\t\t\txmlns=\"http:\/\/www.w3.org\/2000\/svg\"\n\t\t\t\t\tviewBox=\"0 0 24 24\"\n\t\t\t\t\tfill=\"none\"\n\t\t\t\t\tstroke=\"currentColor\"\n\t\t\t\t\tstroke-width=\"2\"\n\t\t\t\t\tstroke-linecap=\"round\"\n\t\t\t\t\tstroke-linejoin=\"round\"\n\t\t\t\t>\n\t\t\t\t\t<path\n\t\t\t\t\t\td=\"M10 15v4a3 3 0 0 0 3 3l4-9V2H5.72a2 2 0 0 0-2 1.7l-1.38 9a2 2 0 0 0 2 2.3zm7-13h2.67A2.31 2.31 0 0 1 22 4v7a2.31 2.31 0 0 1-2.33 2H17\"\n\t\t\t\t\t><\/path>\n\t\t\t\t<\/svg>\n\t\t\t\t<span class=\"sr-only\"> No <\/span>\n\t\t\t<\/button>\n\t\t<\/div>\n\t<\/header>\n\n\t<div class=\"wth-form hidden\">\n\t\t<div class=\"wth-form-wrapper\">\n\t\t\t<div class=\"wth-title\"><\/div>\n\t\t\t\n\t\t\t<textarea class=\"wth-message\"><\/textarea>\n\n\t\t\t<button class=\"btn btn-primary wth-btn-submit\">Send<\/button>\n\t\t\t<button class=\"btn wth-btn-cancel\">Cancel<\/button>\n\t\t\n\t\t<\/div>\n\t<\/div>\n<\/div>\n","protected":false},"excerpt":{"rendered":"<p>This tutorial introduces you to the PL\/SQL package and explain you the reasons that you should use them in your application development.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1418,"menu_order":29,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1590","page","type-page","status-publish","hentry"],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v27.4 - https:\/\/yoast.com\/product\/yoast-seo-wordpress\/ -->\n<title>Oracle PL\/SQL Package<\/title>\n<meta name=\"description\" content=\"This tutorial introduces you to the PL\/SQL package and explain you the reasons that you should use them in your application development.\" \/>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Oracle PL\/SQL Package\" \/>\n<meta property=\"og:description\" content=\"This tutorial introduces you to the PL\/SQL package and explain you the reasons that you should use them in your application development.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/\" \/>\n<meta property=\"og:site_name\" content=\"Oracle Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-05-30T08:44:27+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"851\" \/>\n\t<meta property=\"og:image:height\" content=\"273\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data1\" content=\"3 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\\\/\\\/schema.org\",\"@graph\":[{\"@type\":\"WebPage\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/\",\"name\":\"Oracle PL\\\/SQL Package\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/plsql-package.jpg\",\"datePublished\":\"2017-12-01T08:35:47+00:00\",\"dateModified\":\"2025-05-30T08:44:27+00:00\",\"description\":\"This tutorial introduces you to the PL\\\/SQL package and explain you the reasons that you should use them in your application development.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/plsql-package.jpg\",\"contentUrl\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/12\\\/plsql-package.jpg\",\"width\":851,\"height\":273,\"caption\":\"pl\\\/sql package\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-package\\\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\\\/\\\/www.oracletutorial.com\\\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"PL\\\/SQL Tutorial\",\"item\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/\"},{\"@type\":\"ListItem\",\"position\":3,\"name\":\"PL\\\/SQL Package\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/#website\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/\",\"name\":\"Oracle Tutorial\",\"description\":\"Oracle Tutorial\",\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\\\/\\\/www.oracletutorial.com\\\/?s={search_term_string}\"},\"query-input\":{\"@type\":\"PropertyValueSpecification\",\"valueRequired\":true,\"valueName\":\"search_term_string\"}}],\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"Oracle PL\/SQL Package","description":"This tutorial introduces you to the PL\/SQL package and explain you the reasons that you should use them in your application development.","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/","og_locale":"en_US","og_type":"article","og_title":"Oracle PL\/SQL Package","og_description":"This tutorial introduces you to the PL\/SQL package and explain you the reasons that you should use them in your application development.","og_url":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/","og_site_name":"Oracle Tutorial","article_modified_time":"2025-05-30T08:44:27+00:00","og_image":[{"width":851,"height":273,"url":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package.jpg","type":"image\/jpeg"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"3 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/","url":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/","name":"Oracle PL\/SQL Package","isPartOf":{"@id":"https:\/\/www.oracletutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/#primaryimage"},"image":{"@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/#primaryimage"},"thumbnailUrl":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package.jpg","datePublished":"2017-12-01T08:35:47+00:00","dateModified":"2025-05-30T08:44:27+00:00","description":"This tutorial introduces you to the PL\/SQL package and explain you the reasons that you should use them in your application development.","breadcrumb":{"@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/#primaryimage","url":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package.jpg","contentUrl":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/12\/plsql-package.jpg","width":851,"height":273,"caption":"pl\/sql package"},{"@type":"BreadcrumbList","@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-package\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/www.oracletutorial.com\/"},{"@type":"ListItem","position":2,"name":"PL\/SQL Tutorial","item":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/"},{"@type":"ListItem","position":3,"name":"PL\/SQL Package"}]},{"@type":"WebSite","@id":"https:\/\/www.oracletutorial.com\/#website","url":"https:\/\/www.oracletutorial.com\/","name":"Oracle Tutorial","description":"Oracle Tutorial","potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/www.oracletutorial.com\/?s={search_term_string}"},"query-input":{"@type":"PropertyValueSpecification","valueRequired":true,"valueName":"search_term_string"}}],"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/1590","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages"}],"about":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/types\/page"}],"author":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/comments?post=1590"}],"version-history":[{"count":0,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/1590\/revisions"}],"up":[{"embeddable":true,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/1418"}],"wp:attachment":[{"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/media?parent=1590"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}