{"id":1472,"date":"2017-11-12T17:26:59","date_gmt":"2017-11-12T10:26:59","guid":{"rendered":"https:\/\/oracletutorial.com\/?page_id=1472"},"modified":"2025-06-09T00:02:44","modified_gmt":"2025-06-09T07:02:44","slug":"plsql-anonymous-block","status":"publish","type":"page","link":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/","title":{"rendered":"PL\/SQL Anonymous Block"},"content":{"rendered":"\n<p><strong>Summary<\/strong>: In this tutorial, you will learn about the PL\/SQL anonymous block and how to execute it using SQL*Plus and SQL Developer tools.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='plsql-anonymous-block-overview'>PL\/SQL anonymous block overview <a href=\"#plsql-anonymous-block-overview\" class=\"anchor\" id=\"plsql-anonymous-block-overview\" title=\"Anchor for PL\/SQL anonymous block overview\">#<\/a><\/h2>\n\n\n\n<p>PL\/SQL is a block-structured language whose code is organized into&nbsp;<strong>blocks<\/strong>.<\/p>\n\n\n\n<p>A block consists of three sections:<\/p>\n\n\n\n<ol class=\"wp-block-list\">\n<li>Declaration Section<\/li>\n\n\n\n<li>Executable Section<\/li>\n\n\n\n<li>Exception-handling Section<\/li>\n<\/ol>\n\n\n\n<p>The executable section is mandatory, while the declaration and exception-handling sections are optional.<\/p>\n\n\n\n<p>A block may have a name. <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-function\/\">Functions<\/a> or <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-procedure\/\">Procedures<\/a> are examples of named blocks. Oracle Database stores named blocks in the server so you can reuse them later.<\/p>\n\n\n\n<p>A block without a name is called an <strong>anonymous block<\/strong>. Since anonymous blocks are not saved in the Oracle Database server, they are only for one-time use. However, PL\/SQL anonymous blocks can be helpful for testing purposes.<\/p>\n\n\n\n<p>The following picture illustrates the structure of a PL\/SQL block:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"462\" height=\"301\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block.png\" alt=\"PL\/SQL anonymous block\" class=\"wp-image-1479\" title=\"PL\/SQL anonymous block\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block.png 462w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-300x195.png 300w\" sizes=\"auto, (max-width: 462px) 100vw, 462px\" \/><\/figure>\n\n\n\n<p><strong>1) Declaration section<\/strong><\/p>\n\n\n\n<p>In the declaration section,&nbsp;<span style=\"box-sizing: border-box; margin: 0px; padding: 0px;\">you<a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-variables\/\" target=\"_blank\" rel=\"noopener\"> declare<\/a><\/span><a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-variables\/\">&nbsp;variables<\/a>, allocate memory for <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-cursor\/\">cursors<\/a>, and define data types.<\/p>\n\n\n\n<p><strong>2) Executable section<\/strong><\/p>\n\n\n\n<p>An executable section starts with the keyword <code>BEGIN<\/code> and ends with the keyword <code>END<\/code>. The executable section must have a least one executable statement, even if it is a <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-null\/\"><code>NULL<\/code> statement<\/a> that does nothing.<\/p>\n\n\n\n<p><strong>3) Exception-handling section<\/strong><\/p>\n\n\n\n<p>An exception-handling section that starts with the keyword <code><a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-exception\/\">EXCEPTION<\/a><\/code>. In the exception-handling section, you catch and handle exceptions raised by the code in the execution section.<\/p>\n\n\n\n<p>Note a block itself is an executable statement, therefore you can nest a block within other blocks.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='plsql-anonymous-block-example'>PL\/SQL anonymous block example <a href=\"#plsql-anonymous-block-example\" class=\"anchor\" id=\"plsql-anonymous-block-example\" title=\"Anchor for PL\/SQL anonymous block example\">#<\/a><\/h2>\n\n\n\n<p>The following example shows a simple PL\/SQL anonymous block with one executable section.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-1\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">BEGIN<\/span>\n   DBMS_OUTPUT.put_line (<span class=\"hljs-string\">'Hello World!'<\/span>);\n<span class=\"hljs-keyword\">END<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-1\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The executable section calls the <code>DMBS_OUTPUT.PUT_LINE<\/code> procedure to display the <code>\"Hello World\"<\/code> message on the screen.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\" id='execute-a-plsql-anonymous-block-using-sqlplus'>Execute a PL\/SQL anonymous block using SQL*Plus. <a href=\"#execute-a-plsql-anonymous-block-using-sqlplus\" class=\"anchor\" id=\"execute-a-plsql-anonymous-block-using-sqlplus\" title=\"Anchor for Execute a PL\/SQL anonymous block using SQL*Plus.\">#<\/a><\/h2>\n\n\n\n<p>Once you have the code of an anonymous block, you can execute it using SQL*Plus, a command-line interface for executing SQL statements and PL\/SQL blocks provided by Oracle Database.<\/p>\n\n\n\n<p>The following picture illustrates how to execute a PL\/SQL block using SQL*Plus:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"558\" height=\"176\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-example.png\" alt=\"PL\/SQL anonymous block example\" class=\"wp-image-1473\" title=\"PL\/SQL anonymous block example\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-example.png 558w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-example-300x95.png 300w\" sizes=\"auto, (max-width: 558px) 100vw, 558px\" \/><\/figure>\n\n\n\n<p>First, connect to the Oracle Database server using a username and password.<\/p>\n\n\n\n<p>Second, turn on the server output using the <code>SET SERVEROUTPUT ON<\/code> command so that the <code>DBMS_OUTPUT.PUT_LINE<\/code> procedure will display text on the screen.<\/p>\n\n\n\n<p>Third, type the code of the block and enter a forward slash ( <code>\/<\/code>) to instruct SQL*Plus to execute the block. Once you type the forward slash (\/), SQL*Plus will execute the block and display the <code>Hello World<\/code> message on the screen as shown in the illustrations.<\/p>\n\n\n\n<p class=\"note\">Note that you must execute <code>SET SERVEROUTPUT ON<\/code> command in every session that you connect to the Oracle Database to show the message using the <code>DBMS_OUTPUT.PUT_LINE<\/code> procedure.<\/p>\n\n\n\n<p>To execute the block that you have entered, you use <code>\/<\/code> command instead of typing everything from scratch:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"526\" height=\"129\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-execute-a-block-again.png\" alt=\"plsql anonymous block - execute a block again\" class=\"wp-image-2763\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-execute-a-block-again.png 526w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-execute-a-block-again-300x74.png 300w\" sizes=\"auto, (max-width: 526px) 100vw, 526px\" \/><\/figure>\n\n\n\n<p>If you want to edit the code block, use the <code>edit<\/code> command. SQL*Plus will write the code block to a file and open it in a text editor as shown in the following picture:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"668\" height=\"159\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-edit.png\" alt=\"plsql anonymous block - edit\" class=\"wp-image-2769\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-edit.png 668w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-edit-300x71.png 300w\" sizes=\"auto, (max-width: 668px) 100vw, 668px\" \/><\/figure>\n\n\n\n<p>You can change the contents of the file like the following:<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-2\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">begin<\/span>\n\tdbms_output.put_line(<span class=\"hljs-string\">'Hello There'<\/span>);\n<span class=\"hljs-keyword\">end<\/span>;\n\/<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-2\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Save and close the file. The contents of the file will be written to the buffer and recompiled.<\/p>\n\n\n\n<p>After that, you can execute the code block again; it will use the new code:<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"518\" height=\"128\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-execute.png\" alt=\"plsql anonymous block - execute\" class=\"wp-image-2770\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-execute.png 518w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2019\/08\/plsql-anonymous-block-execute-300x74.png 300w\" sizes=\"auto, (max-width: 518px) 100vw, 518px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='execute-a-plsql-anonymous-block-using-sql-developer'>Execute a PL\/SQL anonymous block using SQL Developer <a href=\"#execute-a-plsql-anonymous-block-using-sql-developer\" class=\"anchor\" id=\"execute-a-plsql-anonymous-block-using-sql-developer\" title=\"Anchor for Execute a PL\/SQL anonymous block using SQL Developer\">#<\/a><\/h2>\n\n\n\n<p>First, connect to the Oracle Database server using Oracle SQL Developer.<\/p>\n\n\n\n<p>Second, create a new SQL file named <code>anonymous-block.sql<\/code> in the <code>C:\\plsql<\/code> directory.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"852\" height=\"611\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer.png\" alt=\"PL\/SQL anonymous block - sql developer\" class=\"wp-image-1474\" title=\"PL\/SQL anonymous block - sql developer\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer.png 852w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-300x215.png 300w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-768x551.png 768w\" sizes=\"auto, (max-width: 852px) 100vw, 852px\" \/><\/figure>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"384\" height=\"218\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-step-2.png\" alt=\"PL\/SQL anonymous block - sql developer - create SQL file\" class=\"wp-image-1475\" title=\"PL\/SQL anonymous block - SQL developer - create SQL file\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-step-2.png 384w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-step-2-300x170.png 300w\" sizes=\"auto, (max-width: 384px) 100vw, 384px\" \/><\/figure>\n\n\n\n<p>Third, enter the PL\/SQL code and execute it by clicking the <strong>Execute<\/strong> button or pressing the <strong>Ctrl-Enter<\/strong> keyboard shortcut.<\/p>\n\n\n\n<figure class=\"wp-block-image\"><img loading=\"lazy\" decoding=\"async\" width=\"479\" height=\"385\" src=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-step-3.png\" alt=\"PL\/SQL anonymous block - SQL developer - execute PL\/SQL Block\" class=\"wp-image-1476\" title=\"PL\/SQL anonymous block - SQL developer - execute PL\/SQL Block\" srcset=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-step-3.png 479w, https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block-sql-developer-step-3-300x241.png 300w\" sizes=\"auto, (max-width: 479px) 100vw, 479px\" \/><\/figure>\n\n\n\n<h2 class=\"wp-block-heading\" id='more-plsql-anonymous-block-examples'>More PL\/SQL anonymous block examples <a href=\"#more-plsql-anonymous-block-examples\" class=\"anchor\" id=\"more-plsql-anonymous-block-examples\" title=\"Anchor for More PL\/SQL anonymous block examples\">#<\/a><\/h2>\n\n\n\n<p>In this example, we first declare a <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-variables\/\">variable<\/a> <code>l_message<\/code> that holds the greeting message. And then, in the execution section, we use the <code>DBMS_OUTPUT.PUTLINE<\/code> procedure to show the content of this variable instead of using a literal string.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-3\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DECLARE<\/span>\n  l_message VARCHAR2( <span class=\"hljs-number\">255<\/span> ) := <span class=\"hljs-string\">'Hello World!'<\/span>;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n  DBMS_OUTPUT.PUT_LINE( l_message );\n<span class=\"hljs-keyword\">END<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-3\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>Here is the output:<\/p>\n\n\n\n<pre class=\"wp-block-preformatted lang:plsql highlight:0 decode:true\">Hello World!<\/pre>\n\n\n\n<p>The following anonymous block example adds an <a href=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-exception\/\">exception-handling<\/a> section that catches <code>ZERO_DIVIDE<\/code> exception raised in the executable section and displays an error message.<\/p>\n\n\n<pre class=\"wp-block-code\" aria-describedby=\"shcb-language-4\" data-shcb-language-name=\"PostgreSQL SQL dialect and PL\/pgSQL\" data-shcb-language-slug=\"pgsql\"><span><code class=\"hljs language-pgsql\"><span class=\"hljs-keyword\">DECLARE<\/span>\n      v_result NUMBER;\n<span class=\"hljs-keyword\">BEGIN<\/span>\n   v_result := <span class=\"hljs-number\">1<\/span> \/ <span class=\"hljs-number\">0<\/span>;\n   <span class=\"hljs-keyword\">EXCEPTION<\/span>\n      <span class=\"hljs-keyword\">WHEN<\/span> ZERO_DIVIDE <span class=\"hljs-keyword\">THEN<\/span>\n         DBMS_OUTPUT.PUT_LINE( <span class=\"hljs-built_in\">SQLERRM<\/span> );\n<span class=\"hljs-keyword\">END<\/span>;<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-4\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">PostgreSQL SQL dialect and PL\/pgSQL<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">pgsql<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<p>The error message is:<\/p>\n\n\n<pre class=\"wp-block-code lang:plsql highlight:0 decode:true\" aria-describedby=\"shcb-language-5\" data-shcb-language-name=\"plaintext\" data-shcb-language-slug=\"plaintext\"><span><code class=\"hljs language-plaintext\">ORA-01476: divisor is equal to zero<\/code><\/span><small class=\"shcb-language\" id=\"shcb-language-5\"><span class=\"shcb-language__label\">Code language:<\/span> <span class=\"shcb-language__name\">plaintext<\/span> <span class=\"shcb-language__paren\">(<\/span><span class=\"shcb-language__slug\">plaintext<\/span><span class=\"shcb-language__paren\">)<\/span><\/small><\/pre>\n\n\n<h2 class=\"wp-block-heading\" id='summary'>Summary <a href=\"#summary\" class=\"anchor\" id=\"summary\" title=\"Anchor for Summary\">#<\/a><\/h2>\n\n\n\n<ul class=\"wp-block-list\">\n<li>PL\/SQL anonymous blocks are unnamed, temporary PL\/SQL code units.<\/li>\n\n\n\n<li>Use anonymous blocks for performing ad-hoc database operations.<\/li>\n<\/ul>\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=\"1472\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/\"\n\t\t\t\tdata-post-title=\"PL\/SQL Anonymous Block\"\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=\"1472\"\n\t\t\t\tdata-post-url=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/\"\n\t\t\t\tdata-post-title=\"PL\/SQL Anonymous Block\"\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 anonymous block and show you how to execute it using SQL*Plus and SQL Developer tools.<\/p>\n","protected":false},"author":1,"featured_media":0,"parent":1418,"menu_order":1,"comment_status":"closed","ping_status":"closed","template":"","meta":{"footnotes":""},"class_list":["post-1472","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>Introduction to PL\/SQL Anonymous Block<\/title>\n<meta name=\"description\" content=\"This tutorial introduces you to the PL\/SQL anonymous block and show you how to execute it using SQL*Plus and SQL Developer tools.\" \/>\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-anonymous-block\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"Introduction to PL\/SQL Anonymous Block\" \/>\n<meta property=\"og:description\" content=\"This tutorial introduces you to the PL\/SQL anonymous block and show you how to execute it using SQL*Plus and SQL Developer tools.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/\" \/>\n<meta property=\"og:site_name\" content=\"Oracle Tutorial\" \/>\n<meta property=\"article:modified_time\" content=\"2025-06-09T07:02:44+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block.png\" \/>\n\t<meta property=\"og:image:width\" content=\"462\" \/>\n\t<meta property=\"og:image:height\" content=\"301\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/png\" \/>\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=\"5 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-anonymous-block\\\/\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-anonymous-block\\\/\",\"name\":\"Introduction to PL\\\/SQL Anonymous Block\",\"isPartOf\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-anonymous-block\\\/#primaryimage\"},\"image\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-anonymous-block\\\/#primaryimage\"},\"thumbnailUrl\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/plsql-anonymous-block.png\",\"datePublished\":\"2017-11-12T10:26:59+00:00\",\"dateModified\":\"2025-06-09T07:02:44+00:00\",\"description\":\"This tutorial introduces you to the PL\\\/SQL anonymous block and show you how to execute it using SQL*Plus and SQL Developer tools.\",\"breadcrumb\":{\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-anonymous-block\\\/#breadcrumb\"},\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-anonymous-block\\\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-anonymous-block\\\/#primaryimage\",\"url\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/plsql-anonymous-block.png\",\"contentUrl\":\"https:\\\/\\\/www.oracletutorial.com\\\/wp-content\\\/uploads\\\/2017\\\/11\\\/plsql-anonymous-block.png\",\"width\":462,\"height\":301,\"caption\":\"PL\\\/SQL anonymous block\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\\\/\\\/www.oracletutorial.com\\\/plsql-tutorial\\\/plsql-anonymous-block\\\/#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 Anonymous Block\"}]},{\"@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":"Introduction to PL\/SQL Anonymous Block","description":"This tutorial introduces you to the PL\/SQL anonymous block and show you how to execute it using SQL*Plus and SQL Developer tools.","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-anonymous-block\/","og_locale":"en_US","og_type":"article","og_title":"Introduction to PL\/SQL Anonymous Block","og_description":"This tutorial introduces you to the PL\/SQL anonymous block and show you how to execute it using SQL*Plus and SQL Developer tools.","og_url":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/","og_site_name":"Oracle Tutorial","article_modified_time":"2025-06-09T07:02:44+00:00","og_image":[{"width":462,"height":301,"url":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block.png","type":"image\/png"}],"twitter_card":"summary_large_image","twitter_misc":{"Est. reading time":"5 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"WebPage","@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/","url":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/","name":"Introduction to PL\/SQL Anonymous Block","isPartOf":{"@id":"https:\/\/www.oracletutorial.com\/#website"},"primaryImageOfPage":{"@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/#primaryimage"},"image":{"@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/#primaryimage"},"thumbnailUrl":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block.png","datePublished":"2017-11-12T10:26:59+00:00","dateModified":"2025-06-09T07:02:44+00:00","description":"This tutorial introduces you to the PL\/SQL anonymous block and show you how to execute it using SQL*Plus and SQL Developer tools.","breadcrumb":{"@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/#breadcrumb"},"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/#primaryimage","url":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block.png","contentUrl":"https:\/\/www.oracletutorial.com\/wp-content\/uploads\/2017\/11\/plsql-anonymous-block.png","width":462,"height":301,"caption":"PL\/SQL anonymous block"},{"@type":"BreadcrumbList","@id":"https:\/\/www.oracletutorial.com\/plsql-tutorial\/plsql-anonymous-block\/#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 Anonymous Block"}]},{"@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\/1472","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=1472"}],"version-history":[{"count":0,"href":"https:\/\/www.oracletutorial.com\/wp-json\/wp\/v2\/pages\/1472\/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=1472"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}