Oracle PL SQL 3
Oracle PL SQL 3
You use these basic elements of PL/SQL to represent real-world objects and operations.
A line of PL/SQL text contains groups of characters known as lexical units, which can be classified as
follows:
• Avoid obscure names such as cpm. Instead, use meaningful names such as
cost_per_thousand.
Reserved Words
• Some identifiers, called reserved words, have a special syntactic meaning to PL/SQL and so
should not be redefined.
• For example, the words BEGIN and END, which bracket the executable part of a block or
subprogram, are reserved.
DECLARE
However, you can embed reserved words in an identifier, as the following example shows:
DECLARE
• Other PL/SQL identifiers, reserved words can be written in lower or mixed case. For a list of
reserved words, see Appendix F.
• literals
• comments
• The following line is not allowed because the reserved words END and IF are joined:
IF x > y THEN high := x; ENDIF; -- not allowed
• You cannot embed spaces in lexical units except for string literals and comments.
• For example, the following line is not allowed because the compound symbol for assignment
(:=) is split:
• To show structure, you can divide lines using carriage returns and indent lines using spaces
or tabs. Compare these IF statements for readability:
| max := x;
| ELSE
| max := y;
| END IF;
Note
• Oracle SQL does not support calling of functions with Boolean parameters or returns.
Functions is sorted into the type of function based on categories such as string/character, conversion,
advanced, numeric/mathematical, and date/time
Oracle / PLSQL: Functions - Listed by Category (techonthenet.com)
Example
DECLARE
variable2 data_type;
BEGIN
END;
Describe when implicit conversions take place and when explicit conversions must be dealt with
Explicit:
• Data must be specified how the data type should be converted.
• An explicit conversion occurs when you use the CONVERT or CAST keywords explicitly in your
query.
Implicit:
• The database engine will convert the data type automatically, a process invisible to the user.
Explicit
• For example, a column date1 written in '21.01.2013'. it is in a varchar format according to the
provided data/table.
• A column date2 which is in '21/01/2013' format. It is a date but provided in a varchar format
as well.
• Example to compare date1 and date2 (whether equal) you must write:
• They are in charge of executing a statement out of multiple given statements based on some
condition.
• The condition will return either true or false. Based on what the condition returns, the
associated statement is executed.
• If Else statements
Case statement