Problems caused by inconsistent Oracle field type design and actual business
During the design of the Oracle table, developers always disagree with the field type. The following example shows how to design the field as number and the result is varchar2, what problems will this cause? Next we will do an experiment.
SQL> create table test (id varchar2 (10 ));
The table has been created.
SQL> declare
2 I number;
3 begin
4 for I in 1 .. 100 loop
5 insert into test values (I );
6 end loop;
7 end;
8/
The PL/SQL process is successfully completed.
SQL> commit;
Submitted.
SQL> select count (*) from test where id <'9'; ---- guess what it is, isn't it 8?
COUNT (*)
----------
89
SQL> select count (*) from test where id <'19 ';
COUNT (*)
----------
11
SQL> select * from test where id <'19 ';
ID
----------
1
10
11
12
13
14
15
16
17
18
100
11 rows have been selected.
Summary: The Oracle comparison string is based on the ASCII code. If the ASCII size of the first letter is equal, the next character is compared, and so on.
For more details, please continue to read the highlights on the next page: