See the excerpt below taken from a PL/SQL tutorial. The part I have an issue with is line 3, where it says salary is of length 6. I don’t understand what that means. In the last line of this excerpt, it declares a variable “of length 10” which is then initialized to “HR Dept” which is certainly not 10 characters. What is meant by length?
DECLARE
salary number (6);
* “salary” is a variable of datatype number and of length 6.
When a variable is specified as NOT NULL, you must initialize the variable when it is declared.
For example: The below example declares two variables, one of which is a not null.
DECLARE
salary number(4);
dept varchar2(10) NOT NULL := “HR Dept”;
Another example:
DECLARE
var_salary number(6);
var_emp_id number(6) = 1116;
1116 is not 6 digits. I’m at a loss.
Maximum length. You’d discover this if you tried to store eleven characters into
deptor if you started making a cool million each year at whatever your job is.It’s no different from when you create tables:
In that case,
20is the maximum length of the name. It doesn’t mean every row has to have a 20-character name.