Hi Everyone, Today's topic is PL/SQL block.
PL/SQL is a block-structured language whose code is organized into blocks.
A PL/SQL block consists of three sections:
Declaration,
Executable,
and Exception-handling sections.
In a block, the executable section is mandatory while the declaration and exception-handling sections are optional.
1) Declaration section
A PL/SQL block has a declaration section where you declare variables, allocate memory for cursors, and define data types.
2) Executable section
A PL/SQL block has an executable section. An executable section starts with the keyword BEGIN and ends with the keyword END. The executable section must have a least one executable statement, even if it is the NULL statement which does nothing.
3) Exception-handling section
A PL/SQL block has an exception-handling section that starts with the keyword EXCEPTION. The exception-handling section is where you catch and handle exceptions raised by the code in the execution section.
Types of PL/SQL blocks :
Named Block : Block who has name is known as Named Block. Functions or Procedures is an example of a named block. A named block is stored into the Oracle Database server and can be reused later.
Anonymous Block : A block without a name is known as anonymous block.
An anonymous block is not saved in the Oracle Database server, so it is just for one-time use. However,
PL/SQL anonymous blocks can be useful for testing purposes.
Example od Anoymous Block:
BEGIN
DBMS_OUTPUT.put_line ('Hello World!');
END;
It display 'Hello World' .
Next, we discuss about the Datatypes used in PL/SQL.
Thank you for reading.
Ask your Doubt or Query in Comment Sections.