当前位置:网站首页>Processing of null value of Oracle notes
Processing of null value of Oracle notes
2022-07-24 20:20:00 【Plant Wutong trees together】
Null value null The reason for this
Oracle Null value in database query null The situation of is generally composed of the following two situations :
1, The data table design is not perfect , For example, there is no foreign key constraint 、 No default value specified 、 Not specified, cannot be empty, etc .
2, Use left join、right join perhaps full join Inquire about , Data fields that are not associated will use null Value padding .
Null value null Hazards of
1, Breaking the integrity of data 、 Readability .
2, influence sql Elegance and performance of statements .
3, Impact on index performance .
4, In particular, it affects numerical calculation .
Null value null To deal with
The best way is to solve the problem once and for all in terms of database design and business data processing logic , But in reality, this is very difficult to do , Here are a few simple examples null Worth the function .
nvl function
Grammar format :nvl( expression , The default value is )
The most commonly used null value processing function ,nvl First, judge whether the expression is empty , If it is null null Then the default value is used to replace , Not null, return the original value of the expression .
Such as select nvl(null,'123') from dual
The result of the query is ’123’, Statement means to use string ’123’ Instead of null value .
decode function
Grammar format :decode( expression , Conditions 1, result 1,··· Conditions n, result n, The default value is )
The expression satisfies the condition 1 Return results 1,··· Meet the conditions n Return results n, If they are not satisfied, the default value is returned .
Be careful : If no default value is specified , Then return to control null.
Such as :select decode(sign(x-y),0,' zero ',1,' just ',' negative ') from dual
Judge x-y The symbol of , If 0 return ‘‘ zero ’’, If 1 return ‘ just ’, Other situations return to ‘ negative ’( contain x,y At least one is null null The situation of ).
coalesce function
Grammar format :coalesce( expression 1,···· expression n, The default value is )
Judge the expression in turn 1,··· expression n, Returns the first non null value null The expression of , If the expression 1,··· expression n If both are empty, the default value is returned .
It is often used when the field value is retrieved by priority in association query .
Such as :
Select coalesce(a.orderid, b.name, c.name, d.name, ' Not obtained ')
From so a
Left Join members_hot b
On a.memberid = b.id
Left Join members c
On a.memberid = c.id
Left Join members_cold id
On a.memberid = d.id
Where create_time >= trunc(Sysdate, 'year')
Use the order form to associate with the member form to obtain the member name , The priority for members_hot ,members,members_cold, If there is no match, it returns ‘ Not obtained ’.
边栏推荐
- [training Day10] tree [interval DP]
- Thymeleaf application notes
- Istio二之流量劫持过程
- Flink window & time principle
- Introduction to fastdfs high availability
- Azide labeled PNA peptide nucleic acid | methylene blue labeled PNA peptide nucleic acid | tyrosine modified PNA | Tyr PNA Qiyue Bio
- Qt| control qscrollbar display position
- Valdo2021 - vascular space segmentation in vascular disease detection challenge (2)
- Sql164 next day retention rate of new users per day in November 2021
- Introduction to WDK development 1- basic environment construction and the first driver (VS2010)
猜你喜欢

Valdo2021 - vascular space segmentation in vascular disease detection challenge (I)

Unity2d~ game practice of decrypting Zhou mu (completed in three days)

Leetcode 560 and the subarray of K (with negative numbers, one-time traversal prefix and), leetcode 438 find all alphabetic ectopic words in the string (optimized sliding window), leetcode 141 circula
![Microservice architecture | service monitoring and isolation - [sentinel] TBC](/img/28/8ca90e9dbd492688e50446f55959ff.png)
Microservice architecture | service monitoring and isolation - [sentinel] TBC

(posted) differences and connections between beanfactory and factorybean

Thymeleaf application notes
![[training Day10] silly [simulation] [greed]](/img/31/94c32e05b498f8ad192f8ec2c500ca.png)
[training Day10] silly [simulation] [greed]

Pix2seq: Google brain proposes a unified interface for CV tasks!

02 | environment preparation: how to install and configure a basic PHP development environment under windows?
![[training Day8] series [matrix multiplication]](/img/00/06f7eb935bfd3c195e2e135197b4bd.png)
[training Day8] series [matrix multiplication]
随机推荐
147-利用路由元信息设置是否缓存——include和exclude使用——activated和deactivated的使用
Mysql8 doesn't seem to support MyISAM partition tables. Does polardb-x support MyISAM partition tables?
Substr and substring function usage in SQL
Lunch break train & problem thinking: on multidimensional array statistics of the number of elements
Todolist case
(posted) differences and connections between beanfactory and factorybean
Understand the domestic open source Magnolia license series agreement in simple terms
Pix2seq: Google brain proposes a unified interface for CV tasks!
英文翻译中文常见脏话
Maya coffee machine modeling
Hook 32-bit function using the method modified to JMP instruction
[training Day10] silly [simulation] [greed]
[trial experience of Yuxin micro Wiota ad hoc network protocol development kit] RT thread BSP Software package production
Each blogger needs to ask himself seven basic questions
C form application treeview control use
Please ask a question. Follow the quick start method. After creating the table, the Flink SQL queries and displays the table structure, but there is an error when it exceeds the limit. What should we
Browser local storage webstroage
What is IDE (integrated development environment)
Excuse me: is Flink 1.14.5 compatible with MySQL CDC 2.1.0
Modbus communication protocol specification (Chinese) sharing