%TYPE and %ROWTYPE in Oracle

%TYPE is used to declare a variable that is of the same type as a specified table’s column.

Emp_number emp_name.emp_nameno%type;

%ROWTYPE is used to declare a record (variable that represents the entire row of a table).

Emp_record emp_name%rowtype;

Another example of declaring variable:

Declare
name varchar2(30);
Select emp_name_name into name from emp_name where emp_nameno = 203456;
Begin
Null;
End;

Any DML statements should be after Begin statement;

Begin
Delete from emp_name where emp_nameno = 24545459;
Commit;
End;

Declaring PL/SQL variables and constants in Oracle

Example of declaring Variableiables:

Variable1 varchar2(100);
Join_date Date;
Variable2 number default 5;
Variable3 number not null := 2;

Not Null means a value may change but it can never be assigned Null.

Variable4 varchar2(20) := Null;
Variable5 varchar2(20) default Null;

Example of declaring Constants:

Variable_constant constant number := 100;

Constants cannot be changed.

You must initialize constants at the time of declaration.