Plsql - Basic SyntaxPL/SQL is a block-structured language, meaning that PL/SQL programs are divided and written in logical blocks of code. Each block consists of three sub-parts:
DECLARE
<declarations section> BEGIN <executable command(s)> EXCEPTION <exception handling> END; The 'Hello World' Example:
DECLARE
message varchar2(20):= 'Hello, World!'; BEGIN dbms_output.put_line(message) END; / The end; line signals the end of the PL/SQL block. To run the code from SQL command line, you may need to type / at the beginning of the first blank line after the last line of the code. When the above code is executed at SQL prompt, it produces the following result:
Hello World
PL/SQL procedure successfully completed. The PL/SQL Identifiers PL/SQL identifiers are constants, variables, exceptions, procedures, cursors, and reserved words. The identifiers consist of a letter optionally followed by more letters, numerals, dollar signs, underscores, and number signs and should not exceed 30 characters. By default, identifiers are not case-sensitive. So you can use integer or INTEGER to represent a numeric value. You cannot use a reserved keyword as an identifier. The PL/SQL Delimiters A delimiter is a symbol with a special meaning. Following is the list of delimiters in PL/SQL:
Program comments are explanatory statements that you can include in the PL/SQL code that you write and helps anyone reading its source code. All programming languages allow for some form of comments. The PL/SQL supports single-line and multi-line comments. All characters available inside any comment are ignored by PL/SQL compiler. The PL/SQL single-line comments start with the delimiter --(double hyphen) and multi-line comments are enclosed by /* and */.
DECLARE
-- variable declaration message varchar2(20):= 'Hello, World!'; BEGIN /* * PL/SQL executable statement(s) */ dbms_output.put_line(message); END; / When the above code is executed at SQL prompt, it produces the following result:
Hello World
PL/SQL procedure successfully completed. PL/SQL Program Units A PL/SQL unit is any one of the following:
|