PLSQL Lexical Unit

Lexical Units

Lexical Units :-A programming language has lexical units that are the building blocks of the language.
PL/SQL lexical units fall within one of the following five groups:
1) Identifiers must begin with a letter and may be up to 30 characters long.
2) Reserved words are words that PL/SQL saves for its own use (such as BEGIN, END, and SELECT).
3) Delimiters are characters that have special meaning to PL/SQL, such as arithmetic operators and quotation marks.
4) Literals are values (character, numeric, or Boolean [true/false]) that are not identifiers.
   123, “Declaration of Independence,” and FALSE are examples of literals.
5) Comments can be either single-line comments (--) or multi line comments (/* */).


Identifiers/Variables :- Variables are used to hold a temporary value.Variables must begin with a letter .

Example:-                       
v_student_id
v_last_name
V_LAST_NAME
apt_#


Substitution Variable:-SQL*Plus allows a PL/SQL block to receive input information with the help of substitution variables. Substitution variables cannot be used to output values, because no memory is allocated for them. SQL*Plus substitutes a variable before the PL/SQL block is sent to the database. Substitution variables usually are prefixed by the ampersand (&) or double ampersand (&&) characters.

Example:-
DECLARE
v_num number:=#
v_result number;
BEGIN
v_result := POWER(v_num, 2);
DBMS_OUTPUT.PUT_LINE ('The value of v_result is: '||v_result);
END;
/


Note:- Here  "num" is the substitution variable .

Reserved Words:- These are the words that can not be used as a variable or literals.

Example:-
BEGIN,DECLARE,END,LOOP,CASE,SELECT,INTO,FROM 



Example:- Smallest program in PLSQL


begin

null;
end;
/

No comments:

Post a Comment