"Ambiguity analysis of Null values"
When it comes to null values, a lot of people are familiar with it, but after a deep understanding, they feel unfamiliar, and their meaning and usage can not be accurately understood. Null in databases and programming languages, the meaning of existence differs from the accompanying meaning.
Null this concept, when generated in the database, there are objections. The meaning of the null value is now the main idea: "Unknown value or indeterminate value". There is a big controversy as to whether it should be considered an unknown value or an indeterminate value.
The null value in the programming language means "null reference", that is, the variable is declared but not instantiated, and memory is not allocated in memory.
Because of the differences in the meaning of null values in programming languages and databases, which makes it difficult to grasp null values, let's talk about what the null value means in the database and what it means and uses in the programming language.
I. Meaning and usage of the null value in the database:
The meaning of the 1.NULL value in the database:
Null values are neither zero nor blank, and null values actually refer to unknown or indeterminate values, missing data.
Usage of 2.NULL values:
The meaning of NULL in the database is undefined, which allows the database operator to distinguish between data that is deliberately recorded as zero and data that is not recorded in the system, or intentionally entering null data.
The effect of the uncertainty of the 3.NULL value:
(1) It cannot be used in a calculation or comparison (value).
(2) Null values are not equal to each other, so the size cannot be compared between null. (analogous to the comparison between infinity in mathematics)
(3) columns that contain null values are ignored when calculating aggregate functions such as AVG, SUM, MAX count.
(4) When a column with a null value appears in the query GROUP BY clause, only one row in the query output contains a null value.
4. How null is handled for various database platforms:
(1) in the Oracle database, a null string is inserted with a null value.
(2) In databases such as SQL Server, MySQL, and so on, inserts an empty string in the varchar and char columns.
Two The meaning and usage of null values in programming languages:
Meaning and usage of null values in programming languages (main programming Language: object-oriented languages such as C#,java)
1. Partitioning of types in the object-oriented programming language (main programming language: C++,c#,java):
The object-oriented programming language divides data types into: value types and reference types. (both can be generic types)
(Note: c++,c# has a third type: pointer type)
Description: The difference between a value type and a reference type---value-type variables directly contain their data, and variables of reference types only hold references to their data, and data is often referred to as objects. (Any type of value can be treated as an object)
2. Null meanings in programming languages:
Null reference (the variable is defined only, but not assigned), and Null is compatible with all reference types, representing the absence of an instance.
3. The meaning of null values in the data type:
(1). Value type: Any value type variable that is a value type of a nullable value type can contain a null value, and for a value type that is not nullable, a corresponding nullable value type represents a set of values that are the same as it and a null value.
(2). BOOL Type: An integer of 0 or floating-point zero, or null pointer, can be represented as a Boolean false, or True, in C/C + +, and the conversion must be compared by displaying an integer or floating-point value to 0, or by comparing the object reference and null;
(Note: A non-Boolean value cannot be converted to a Boolean value when comparing null.) )
(3). Reference type: The value of a reference type is a reference to an instance of a type, which is called an object, and the special only null and all reference types are compatible, representing the absence of an instance.
The meaning of the 4.NULL value in the programming language:
(1). Empty object: is a variant called an empty iterator model, which enables operations that traverse individual nodes in a composite hierarchy to be transparent to the client (the client can use the same logic to traverse the combination and leaf nodes)
(2). The meaning of an empty object: The most useful thing is that it is closer to the data because the object represents an entity within the problem space.
Three. Null values data manipulation processing between the programming language and the database:
1. How data in the programming language is written to the database:
(1). In connection with the database through a database connection (using the jdbc,c# application's corresponding data source in Java), after the connection succeeds, the data in the database is obtained, and NULL in SQL is mapped to NULL in Java (C #). This can lead to the thought of Null==null in Java (C #), where Null= NULL is also present in SQL.
2. How the programming language extracts the value from the database to determine if it is null:
(1). Convert the extracted data into a string type and then make a judgment.
(2). Use the methods provided by the language to judge. (Use DBNull or IsNull in C #)
What do you know about the wonderful null value? 》