Declaration section: This section begins with the keyword DECLARE. This is an optional part that defines all variables, cursors, subroutines and other elements used in the program.
Executable command part: this part is included between the keywords BEGIN and END, and is a mandatory part. It consists of executable oracle statements of the program. There should be at least one line of executable code, which can be just an empty command, indicating that nothing has been done.
EXCEPTION handling section: this section begins with the keyword exception. This is an optional section that contains exceptions that handle errors in the handler.
Each oracle statement is preceded by a semicolon (; ) end. Use BEGIN and END to nest oracle blocks in other oracle blocks. The following is the basic structure of the Poracle block.
Hello World example:
End; Rows represent the end of an oracle block. To run code from the oracle command line, you need to type the/character after the last line of the code. When the above code is executed at the oracle prompt, it will produce the following results:
Oracle identifiers: Oracle identifiers are constants, variables, exceptions, procedures, cursors and reserved words. The identifier consists of a letter, optionally followed by multiple letters, numbers, dollar symbols, underscores and number symbols, and shall not exceed 30 characters.
By default, identifiers are case-insensitive. For example, you can use INTEGER or integer to represent a numeric value. Reserved keywords cannot be used as identifiers.
Extended data
Oracle annotator: Annotate explanatory words that can be included in written Oracle code and help others read the source code. All programming languages allow some form of annotation.
Oracle supports single-line and multi-line comments. Oracle compiler ignores all characters in comments. Oracle single-line comments begin with the separator-(double hyphen), and multi-line comments are enclosed with/* and */.
When the above code is executed at the oracle prompt, it will produce the following results:
The name of an oracle variable consists of optional letters, numbers, dollar ($) symbols, underscores and number symbols, and cannot exceed 30 characters. By default, variable names are case-insensitive. Reserved oracle keywords cannot be used as variable names.
Oracle programming language allows the definition of various types of variables, such as date and time data types, records, collections, etc. We will introduce it in later chapters. In this chapter, only the basic variable types are studied.