42.2. Structure of PL/oraSQL

42.2.1. Anonymous Block
42.2.2. Comments

PL/oraSQL is a block-structured language.A function, procedure, package, trigger or anonymous block contains a block structure, and we call all the parts contained in the anonymous block a block structure.

42.2.1. Anonymous Block

An anonymous block is defined as:

[ DECLARE
    declarations ]
BEGIN
    statements
[ EXCEPTION 
    Exception-handling part ]
END;
/

Each declaration and each statement within a block is terminated by a semicolon. A block that appears within another block must have a semicolon after END, as shown above; however the final END that concludes a function body does too require a semicolon. where / is the end character of plorasql lower block structure.

Tip

A common mistake is to write a semicolon immediately after BEGIN. This is incorrect and will result in a syntax error. Anonymous blocks currently do not support the use of <<label>>.

For example, use an anonymous block to output a value of 'quantity':

DECLARE
  quantity integer := 80;
BEGIN
  DBMS_OUTPUT.PUT_LINE('Quantity here is '||quantity);  -- Prints 80
END;
/

Before using the DBMS_OUTPUT.PUT_LINE function, you need to turn on the print permission.

 select dbms_output.serveroutput(true);

Of course, this function can only be used in Oracle compatibility mode.

 set lightdb_syntax_compatible_type to 'oracle';

42.2.2. Comments

The PL/oraSQL compiler ignores comments. Their purpose is to help other application developers understand your source text. Typically, you use comments to describe the purpose and use of each code segment. You can also disable obsolete or unfinished pieces of code by turning them into comments.

42.2.2.1. Single-Line Comments

A single-line comment begins with -- and extends to the end of the line. This example has three single-line comments.

DECLARE
  howmany     NUMBER;
  num_tables  NUMBER;
BEGIN
  -- Begin processing
  SELECT COUNT(*) INTO howmany
  FROM USER_OBJECTS
  WHERE OBJECT_TYPE = 'TABLE'; -- Check number of tables
  num_tables := howmany;       -- Compute another value
END;
/

42.2.2.2. Multiline Comments

A multiline comment begins with /*, ends with */, and can span multiple lines.

BEGIN
  /*
  IF 2 + 2 = 4 THEN
    some_condition := TRUE;
  END IF;
  */
  NULL;
END;
/