Problems caused by inconsistent Oracle field type design and actual business

Source: Internet
Author: User

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:

  • 1
  • 2
  • Next Page

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.