![]() ![]() Third, type the code of the block and enter a forward slash ( /) to instruct SQL*Plus to execute the block. Second, turn on the server output using the SET SERVEROUTPUT ON command so that the DBMS_OUTPUT.PUT_LINE procedure will display text on the screen. The following picture illustrates how to execute a PL/SQL block using SQL*Plus:įirst, connect to the Oracle Database server using a username and password. Once you have the code of an anonymous block, you can execute it using SQL*Plus, which is a command-line interface for executing SQL statement and PL/SQL blocks provided by Oracle Database. Execute a PL/SQL anonymous block using SQL*Plus The executable section calls the DMBS_OUTPUT.PUT_LINE procedure to display the "Hello World" message on the screen. The following example shows a simple PL/SQL anonymous block with one executable section.Ĭode language: SQL (Structured Query Language) ( sql ) Note a block itself is an executable statement, therefore you can nest a block within other blocks. The exception-handling section is where you catch and handle exceptions raised by the code in the execution section. The executable section must have a least one executable statement, even if it is the NULL statement which does nothing.Ī PL/SQL block has an exception-handling section that starts with the keyword EXCEPTION. An executable section starts with the keyword BEGIN and ends with the keyword END. The following picture illustrates the structure of a PL/SQL block:Ī PL/SQL block has a declaration section where you declare variables, allocate memory for cursors, and define data types.Ī PL/SQL block has an executable section. However, PL/SQL anonymous blocks can be useful for testing purposes. An anonymous block is not saved in the Oracle Database server, so it is just for one-time use. A named block is stored into the Oracle Database server and can be reused later.Ī block without a name is an anonymous block. Functions or Procedures is an example of a named block. In a block, the executable section is mandatory while the declaration and exception-handling sections are optional.Ī PL/SQL block has a name. A PL/SQL block consists of three sections: declaration, executable, and exception-handling sections. PL/SQL is a block-structured language whose code is organized into blocks. ![]() Summary: in this tutorial, you will learn about the PL/SQL anonymous block and how to execute it using SQL*Plus and SQL Developer tools. ![]()
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |