Google News
logo
PL/SQL - Interview Questions
Explain the PL/SQL block with an example.
PL/SQL block consists of three sections : declaration, executable and exception-handling sections. The executable section is mandatory. There are two types of blocks: named and anonymous.
 
Named blocks are functions and procedures which are stored in the database server and can be reused. Anonymous blocks are for one time use and are not stored in the server. Example :

 

DECLARE

 message VARCHAR2(255):= 'Welcome to PL/SQL';
 byzero NUMBER;

BEGIN

   DBMS_OUTPUT.put_line (message);
   byzero := 1/0;

   EXCEPTION

  WHEN ZERO_DIVIDE THEN
 DBMS_OUTPUT.PUT_LINE(SQLERRM);
END;
Advertisement