当前位置:网站首页>[Oracle] is there a "time" data type in oracle-- Research on Oracle data types
[Oracle] is there a "time" data type in oracle-- Research on Oracle data types
2022-06-21 17:44:00 【DarkAthena】
Preface
Oracle Are there in “time” Data type ? Most familiar oracle Most people will say no , But is this the case ?
The following picture will certainly surprise many people 
Analysis methods
Front dish
oracle There are many things that will not be written in the document , You need to find out for yourself , But fortunately, oracle There is a lot of code that is visible plsql Language , So you can use these visible codes and logical analysis to understand oracle Of “ Customary practice ”.
Like functions , If you only look at official documents , contrast DBA_OBJECTS Inside sys Under the user function, You will find that many functions are missing from the official documentation . In addition, there are quite a few functions in official documents , stay DBA_OBJECTS There's no , However, the automatic code completion function of the tool can complete the functions , So it's natural to think , What mechanism is this ?
select * from dba_objects h where h.object_type='FUNCTION' AND OWNER='SYS';
select * from dba_objects h where h.object_name='NVL';
dba_objects There is no corresponding name in the , Maybe these names are in dba_source Are there in
select * from dba_source h where lower(h.text) like '%function%nvl(%' and owner='SYS';

So I am sys The user found standard This package, There are many familiar functions in it , And it also conforms to my previous understanding :
In the same schema Next , Only functions in the package can have duplicate names , Each function has a certain parameter type and number
If nvl This function supports multiple types in Oracle Is just a function , Nature does not conform to this logic , So nature analyzes a mechanism :
It can be used without package name , And you can pass in functions of the same name with different types of parameters , It's all defined in standard In this bag .
Dinner
And then back to type, First, create tables in the usual way , To enter a paragraph sql, You will find that the tool automatically prompts "time" This keyword and "time with tz" This type, Of course, both of them will be wrong .


But that means oracle I won't support it time What's the type ?
If you ask oracle Which types are supported in , It's OK to read the official documents first , But because of the previous experience , You must suspect that the document is incomplete , Will check dba_types, That's too much , Take a glance , Add one owner Empty condition , Namely oracle All in “ basic ” data type , Except for the fact that "time" Outside this type , It is also found that the names of some types are not exactly the same as those actually used , For example, the common "PLS_INTEGER" Name and... In the view CODE Are all "PL/SQL PLS INTEGER".
select * from dba_types where owner is null;

We know , about PLS_INTEGER type , Can only be used in stored procedures , Cannot be used as a table field , This is because oracle It is limited . You can guess "PLS" Built in type at the beginning , Can not be used to create tables 
however , You'll find that , This report is wrong , Even with the top time The types of errors reported are different .
Think of the previous standard The mechanism of the package , The name you want to use is also defined in this package , Open it and see .
type TIME is new DATE_BASE;
type TIMESTAMP is new DATE_BASE;
type "TIME WITH TIME ZONE" is new DATE_BASE;
type "TIMESTAMP WITH TIME ZONE" is new DATE_BASE;
type "INTERVAL YEAR TO MONTH" is new DATE_BASE;
type "INTERVAL DAY TO SECOND" is new DATE_BASE;
SUBTYPE TIME_UNCONSTRAINED IS TIME(9);
SUBTYPE TIME_TZ_UNCONSTRAINED IS TIME(9) WITH TIME ZONE;
SUBTYPE TIMESTAMP_UNCONSTRAINED IS TIMESTAMP(9);
SUBTYPE TIMESTAMP_TZ_UNCONSTRAINED IS TIMESTAMP(9) WITH TIME ZONE;
SUBTYPE YMINTERVAL_UNCONSTRAINED IS INTERVAL YEAR(9) TO MONTH;
SUBTYPE DSINTERVAL_UNCONSTRAINED IS INTERVAL DAY(9) TO SECOND (9);

In the title of this article time type , stay oracle It does , However, there are limitations in use , And this limitation and pls The type of performance is not the same , The error reported during table creation is not an invalid data type , Instead, there are fewer attributes or keywords , But according to package In the time The use of type , It is also impossible to create tables .
create table test_time_table(a time(9));

then , Try again in another way .
You can't create a table , Let's start with a function return try
create or replace function test_time_func return time is
begin
return '21:19:00';
end;
/
select test_time_func from dual;

Found that it could be select !!
Need to know oracle Although there are boolean type , Can't be select Of , This further illustrates time Types and those pls The types are different .
This function is implicitly converted directly by me , There was no error , Then try it directly cast
select cast('12:34:56' as time) from dual

Yes !, For it to_char
select to_char(cast('12:34:56' as time),'hh24:mi:ss') from dual

No problem , It's all right time type , even to_char Formatting can be used !
So , Try create table as, Let's see how it works 
no way , Then try create view as , because view You can also view field types 
It looks like time(0)(7) ?
One more first create table as select * from View 
So far , Basically, we can judge , stay dba_types in owner Empty type , Distinguish by what you can use , At least it can be divided into 3 class ,
- It can be used everywhere ( representative :varchar2/number/date)
- Only in plsql What can be used in ( representative :boolean/pls_integer)
- Only create table What can't be used in , But can be used as a column select、 Can be used as a view field type 、 Can be in plsql Use in ( representative :time)
Then continue to study this time The meaning of the last two numbers .
go back to standard package , See these two lines
SUBTYPE TIME_UNCONSTRAINED IS TIME(9);
SUBTYPE TIME_TZ_UNCONSTRAINED IS TIME(9) WITH TIME ZONE;
We try to build view To see what the fields created with these two field types look like 

The range of the first number is 0-9.
But ,0 To 9 The number of seconds is complete , I think I have seen colleagues discuss timestamp(6) and timestamp(9), Naturally, it is associated with a similar meaning , That is, this number represents the number of decimal places after the second , But I forgot how to format it in seconds , Just check it out nls_database_parameters, This check , Another parameter that I didn't notice before 
here time It's clear that ...
The following sql Verified my conjecture
select to_char(cast('12:34:56.987654321' as time(5)),'hh24:mi:ss XFF') from dual;

Next is the 2 A digital 
It seems wrong , There was no 7, First dump have a look 
find 7 了 , It turns out that No 2 A digital 7, It means time Number of bytes occupied by type data , And this length will not be due to time Vary with accuracy , Always fixed 7 position . As for those with time zones time, It's fixed 9 position 
Dessert
time The content of the type is basically studied , And then back to standard package , Take a look at some of the first code
type DATE is DATE_BASE;
type NUMBER is NUMBER_BASE;
subtype FLOAT is NUMBER; -- NUMBER(126)
subtype REAL is FLOAT;
You can see that there is *_base In this way , Search the whole bag , You can get the following 6 Kind of
- DATE_BASE
- NUMBER_BASE
- CHAR_BASE
- BLOB_BASE
- CLOB_BASE
- BFILE_BASE
"base" It means basic , in other words ,oracle All the basic types it uses , Divided into this 6 Categories: .
then "type NUMBER is NUMBER_BASE" That is to say NUMBER It belongs to NUMBER_BASE One of ;
"subtype FLOAT is NUMBER;" namely FLOAT by NUMBER Subtypes of ( Here we need to pay attention to , Binary stored values of subtypes , Not necessarily the same as the original type , such as “subtype BINARY_FLOAT is NUMBER;”).
Keep looking at this bag , Would be right oracle Have a deeper understanding , Of course, this article will not continue , Leave a little space for readers to explore .
summary
Although the title of this article is "time" type , And the main line of the article is also around “time” Type expansion , But what is more, the author himself dares to “ authority ” The question of , As well as the record of the deep excavation of the unknown with logical thinking and experiments . I hope readers will learn more than “oracle Are there in time type ” This conclusion , I also hope that readers will work in the future , Have the exploration spirit and logical thinking ability to dig deep into problems .
- The author of this article :DarkAthena
- Link to this article :https://www.darkathena.top/archives/oracle-time-data-type-is-exists
- Copyright notice : All articles in this blog except special statement , All adopt CC BY-NC-SA 3.0 license agreement . Reprint please indicate the source !
边栏推荐
- 《MATLAB 神经网络43个案例分析》:第27章 LVQ神经网络的预测——人脸朝向识别
- 鱼佬:电信客户流失预测赛方案!
- 一招教你通过焱融 SaaS 数据服务平台+ELK 让日志帮你做决策
- Application architecture principles
- JetPack compose 状态提升(二)
- Google play application signature key certificate, upload signature certificate difference
- ViT杀疯了,10+视觉Transformer模型详解
- Two understandings of Bayes formula
- PTA L3-032 关于深度优先搜索和逆序对的题应该不会很难吧这件事 (30 分)
- Volcano engine + Yanrong yrcloudfile, driving new growth of data storage
猜你喜欢

Two understandings of Bayes formula

Accelerate the implementation of cloud native applications, and Yanrong yrcloudfile and Tianyi cloud have completed the Compatibility Certification

全国行政区划

窗帘做EN 1101易燃性测试过程是怎么样的?

3DE 网格坐标点与物体的附加

3DE 运动轮廓数据修改

Common setting modes

Ease of fire test for silicone rubber glass fiber pipe en45545

How to connect the Internet - FTTH

node服务器 res.end()中写中文,客户端中乱码问题的解决方法
随机推荐
不是一流大学毕业,却通过自学软件测试,进了阿里年薪初始22K
MySQL 1055错误-this is incompatible with sql_mode=only_full_group_by解决方案
加密大崩盘,Web3游戏到底还有没有未来?5篇论文深度探讨
算法--按奇偶性交换后的最大数字(Kotlin)
Jetpack compose phase
Kotlin DSL build
深入理解图注意力机制
How to perform en45545 fire test for battery shell
软件测试体系学习及构建(14)-测试基础之软件测试和开发模型概述
泊松抽样与伯努利抽样主要联系与区别
How many items should the indoor intumescent fire retardant coating meet according to BS 476-21 fire resistance standard?
如何写好技术文档 Software Engineering at Google
list的使用
#Vscode工具#
iframe跨域传值
Google play application signature key certificate, upload signature certificate difference
Vscade tool
Volcano engine + Yanrong yrcloudfile, driving new growth of data storage
Nacos注册中心-----从0开始搭建和使用
3de 3D model View ne voit pas comment ajuster