当前位置:网站首页>Analysis on the query method and efficiency of Oracle about date type
Analysis on the query method and efficiency of Oracle about date type
2022-07-26 08:34:00 【ZenPower】
background : Several positions ETL Link passed sqoop Extract a Oracle Business table , Suddenly on a certain day sqoop Export error , Retrying still failed . After querying the source database, it is found that the current incremental extraction sql It takes a long time , involve oracle database date Query efficiency in type comparison .
- Original incremental query sql
select * from ora_table where to_char(update_time,'yyyymmdd') = '20220222';
notes : stay Oracle Source library update_time Field is date type , Above sql It means to take 2022-02-22 A day's record
- Problem cause analysis
After testing, it is found that the original incremental query sql It is particularly slow to query the source database , Think for a moment and realize ,oracle database date All types of data storage use Time stamp , That is, the final comparison is still with Numerical comparison . and to_char() After the conversion, the comparison becomes Character comparison 了 , That is, by bytecode comparison , By comparison , It must be more efficient in numerical comparison .
- Optimize the query method
Since the use of date Direct comparison of types is more efficient , Then you need to convert the characters to be compared to date type
select * from ora_table where update_time = to_date('20220222','yyyy-mm-dd');
Use the above sql when , Here's the problem ,to_date() Function parameters can only be transferred to date ( Without time ) Words , The converted date value will be added with time by default 00:00:00, This is used for conditional judgment , I can't get it 2022-02-22 Recorded on this day
We can use to_char() Format the function to_date('20220222','yyyy-mm-dd') This date Type value to verify
select to_char(to_date('20220222','yyyy-mm-dd'),'yyyy-mm-dd hh24:mi:ss) from ora_table where rownum=1;
You will find that the obtained value is 2022-02-22 00:00:00, If you match by date type , take 2022-02-22 The record of this day , We hope that the value range should be 2022-02-22 00:00:00 to 2022-02-22 23:59:59( Left and right closed interval ), So we need to to_date() Add a time limit when formatting functions , below 2 Both schemes can be realized
Scheme 1
-- adopt between..and( Closed interval )
select * from ora_table where update_time between to_date('20220222 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('20220222 23:59:59','yyyy-mm-dd hh24:mi:ss');
-- adopt >= and <=
select * from ora_table where update_time >= to_date('20220222 00:00:00','yyyy-mm-dd hh24:mi:ss') and update_time <= to_date('20220222 23:59:59','yyyy-mm-dd hh24:mi:ss');
But it is recommended to use >= Symbol , because between..and
If you don't want to restrict the time format , You can also add one day to the right range , And then through < To achieve , So the value range is 2022-02-22 00:00:00 to 2022-02-23 00:00:00( Left closed , Right open )
Option two
select * from ora_table where update_time >= to_date('20220222','yyyy-mm-dd') and update_time < to_date('20220223','yyyy-mm-dd');
边栏推荐
- 【EndNote】文献模板编排语法详解
- The second lesson is the construction of development environment
- Vscode utility shortcut
- Number of briquettes & Birthday Candles & building blocks
- Status management bloc provider geTx
- Spark scheduling analysis
- Alphabetic string
- Inaccurate problem of flutter fijkplayer seekto
- 请问现在flinkcdc支持sqlserver实例名方式连接吗?
- Write common API tools swagger and redoc
猜你喜欢
Bee guitar score high octave and low octave
苹果强硬新规:用第三方支付也要抽成,开发者亏大了!
Super nice navigation page (static page)
Leetcode and query question summary
mysql函数汇总之日期和时间函数
[GUI] swing package (window, pop-up window, label, panel, button, list, text box)
Kotlin data type
OSPF summary
vscode 实用快捷键
Why reserve a capacitor station on the clock output?
随机推荐
BGP -- Border Gateway Protocol
Basic music theory rhythm connection problem, very important
SPSS uses kmeans, two-stage clustering and RFM model to study the behavior law data of borrowers and lenders in P2P network finance
Flex three column layout
Use of room database in kotlin
2022-7-4 personal qualifying 1 competition experience
Memory management based on C language - Simulation of dynamic partition allocation
Code cloud change remote warehouse command
The second lesson is the construction of development environment
[C language] programmer's basic skill method - "creation and destruction of function stack frames"
2022-7-8 personal qualifying 5 competition experience (supplementary)
监控用户积分变化的两种方式
吉他五线谱联系 茉莉花
Differences and connections of previewkeydown, Keydown, keypress and Keyup in C WinForm
Day 3 homework
B title: razlika priority queue approach
BGP routing principle
内存管理-动态分区分配方式模拟
【EndNote】文献类型与文献类型缩写汇编
各位老师,请问在flinkcdc中,sqlserver如何获取到ddl?