Using an error function takes the maximum value max of the string table and Cause Problems in Oracle

In the development process, encountered a problem that has troubled me for quite a while, the question is this:

This is a table of an Oracle database, OrderNo a serial number, plus 1 each time data is inserted

We take the maximum value of the serial number, arguably, orderno maximum should be 11, but the fact is this:

Take out the largest is 9, not 11, depressed for several days, finally let me find the reason:

orderno construction time table definition is varchar2, rather than the number, resulting in the maximum value is taken 9

:max(column_name)

Column_name column data may be numeric, string, date, or time data types. MAX () / MIN () function returns a single value of the column of the same type of data being transferred.

The maximum value of the character data are arranged in order from A ~ Z in accordance with the first letter, the more backward, the greater its value. Of course, the characters are arranged according to their phonetic spelling, if the first character the same, the next character, and so on.

Therefore, it is possible to know, for a maximum take character data to compare the first character, find the greatest returns this value, the latter would not have compared the character, so we need to get out and not the same.

Solution: character-type data type becomes a value on it, use to_number function (this approach is applicable to strings of numeric type, did not come across other types of such problems).

ps: when think how to find a solution so simple, but in fact at the time of the initial encounter this problem, it still felt very complex, and a look ignorant force o ((⊙﹏⊙)) o has been studying is not write sql statement there are problems, but not reported in the development of a specific fault, I can only go one way one way to test to find the cause of the problem, but fortunately, persevering, and finally found the reason.

Some bug that looks difficult batch, wait until resolved, will find so so simple, so do not be intimidated by the bug, you can of.

Published 16 original articles · won praise 22 · views 80000 +

Guess you like

Origin blog.csdn.net/c_staunch/article/details/100132627