PLSQL

PL/SQL User-Defined Subtypes.

PL/SQL User-Defined Subtypes.

The subtype is said to be the subset of another data type, that is known to be its base type. The subtype has its same valid operations as its base type, but only subset of its valid values. It predefines several subtypes in the package STANDARD. Like, PL/SQL predefines the subtypes CHARACTER and INTEGER as given below:

SUBTYPE CHARACTER IS CHAR;
SUBTYPE INTEGER IS NUMBER (38,0);

We can define and also use our own subtypes. The following program illustrates defining and using a user-defined subtype:

DECLARE

SUBTYPE name IS char(20);

SUBTYPE message IS varchar2(100);

Salutation name;

BEGIN

Salutation: = ‘learner’;

Greetings: = ‘welcome to great learning’;

dbms_output.put_line(‘Heloo’ || salutation || greetings);

END;

/

When we execute the code is executed at the SQL prompt, it gives the following output:

Hello Learner Welcome to great learning

PL/SQL procedure successfully completed.

NULLS in PL/SQL

These NULL values represent missing or the unknown data and they are not an integer, a character, or any other specific data type. However, NULL is not the same as empty data string or the null character value ‘\0’. Null can be assigned but it cannot be equated with anything, including itself.