Home Database Mysql Tutorial Oracle数据库中关于日期和时间字段类型

Oracle数据库中关于日期和时间字段类型

Jun 07, 2016 pm 03:25 PM
oracle about Field database date time type

Oracle数据库 与日期有关的有三种类型:date,timestamp与interval。DATE和TIMESTAMP类型存储精度可变的固定日期/时间,二者区别是,后者秒可以精确到小数,另外还可以有时区之分。。INTERVAL类型可以很容易地存储一个时间量,如“8个小时”或“30天”。将两

Oracle数据库

与日期有关的有三种类型:date,timestamp与interval。DATE和TIMESTAMP类型存储精度可变的固定日期/时间,二者区别是,后者秒可以精确到小数,另外还可以有时区之分。。INTERVAL类型可以很容易地存储一个时间量,如“8个小时”或“30天”。将两个日期相减,就会得到一个时间间隔(INTERVAL);例如,将8小时间隔加到一个TIMESTAMP上,会得到8小时以后的一个新的TIMESTAMP。

操作日期有关字段的时候,最好显示地指定日期或时间格式,比如:

Insert into t ( date_column ) values ( to_date( '01/02/2003', 'DD/MM/YYYY' ) );避免各种格式造成混乱。

1. DATE类型介绍

DATE类型是一个7字节的定宽日期/时间数据类型。它总是包含7个属性,包括:世纪、世纪中哪一年、月份、月中的哪一天、小时、分钟和秒。这七个字节分别存储的是这7个属性,比如:2005-12-05 12:30:43存储的是120,105,12,5,12,31,44。世纪和年份分别加了100,分钟和秒钟分别加了1。世纪和年份加100是为了区分公元前和公元后。我们经常使用这样的条件,Where to_char(date_column,'yyyy') = '2005',其实这个地方可以换成:Where trunc(date_column,'y') = to_date('01-jan-2005','dd-mon-yyyy')。因为,trunc函数是在日期上将年份后面5个字节清空,而to_char函数,还要转换成字符串。当然,如果能够不使用函数最好,比如:created >= to_date('01-jan-2005','dd-mon-yyyy') and created

更多Oracle资料、视频教程:

http://2.taobao.com/item.htm?id=42922011874&spm=686.1000925.0.0.ZVvkz6&mt=


如何向date增减时间

1. 使用NUMTODSINTERVAL内置函数来增加小时、分钟和秒。比如:DATE+NUMTODSINTERVAL(n,'minute')

2. 加一个简单的数来增加天。比如:DATE+n

3. 使用ADD_MONTHS内置函数来增加月和年。比如:ADD_MONTHS(DATE,n)

因为,ADD_MONTHS函数专门处理月末日期。它实际上会为我们完成日期的“舍入”;例如,如果向一个有31天的月增加1个月,而且下一个月不到31天,ADD_MONTHS就会返回下一个月的最后一天。比如:向2000年2月29日增加1个月,得到的是2000年3月31日。2月29日是该月的最后一天,所以ADD_MONTHS返回了下一个月的最后一天。

2. TIMESTAMP类型介绍

TIMESTAMP类型与DATE非常类似,只不过另外还支持小数秒和时区。

语法如下: TIMESTAMP(n),n可选,用于指定TIMESTAMP中秒分量的小数位数,可以取值为0~9.如果指定0,TIMESTAMP在功能上则与DATE等价。

更多Oracle资料、视频教程:

http://2.taobao.com/item.htm?id=42922011874&spm=686.1000925.0.0.ZVvkz6&mt=


Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

AI Hentai Generator

AI Hentai Generator

Generate AI Hentai for free.

Hot Article

R.E.P.O. Energy Crystals Explained and What They Do (Yellow Crystal)
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. Best Graphic Settings
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌
R.E.P.O. How to Fix Audio if You Can't Hear Anyone
3 weeks ago By 尊渡假赌尊渡假赌尊渡假赌

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)

How long will Oracle database logs be kept? How long will Oracle database logs be kept? May 10, 2024 am 03:27 AM

The retention period of Oracle database logs depends on the log type and configuration, including: Redo logs: determined by the maximum size configured with the "LOG_ARCHIVE_DEST" parameter. Archived redo logs: Determined by the maximum size configured by the "DB_RECOVERY_FILE_DEST_SIZE" parameter. Online redo logs: not archived, lost when the database is restarted, and the retention period is consistent with the instance running time. Audit log: Configured by the "AUDIT_TRAIL" parameter, retained for 30 days by default.

How much memory does oracle require? How much memory does oracle require? May 10, 2024 am 04:12 AM

The amount of memory required by Oracle depends on database size, activity level, and required performance level: for storing data buffers, index buffers, executing SQL statements, and managing the data dictionary cache. The exact amount is affected by database size, activity level, and required performance level. Best practices include setting the appropriate SGA size, sizing SGA components, using AMM, and monitoring memory usage.

Oracle database server hardware configuration requirements Oracle database server hardware configuration requirements May 10, 2024 am 04:00 AM

Oracle database server hardware configuration requirements: Processor: multi-core, with a main frequency of at least 2.5 GHz. For large databases, 32 cores or more are recommended. Memory: At least 8GB for small databases, 16-64GB for medium sizes, up to 512GB or more for large databases or heavy workloads. Storage: SSD or NVMe disks, RAID arrays for redundancy and performance. Network: High-speed network (10GbE or higher), dedicated network card, low-latency network. Others: Stable power supply, redundant components, compatible operating system and software, heat dissipation and cooling system.

How much memory is needed to use oracle database How much memory is needed to use oracle database May 10, 2024 am 03:42 AM

The amount of memory required for an Oracle database depends on the database size, workload type, and number of concurrent users. General recommendations: Small databases: 16-32 GB, Medium databases: 32-64 GB, Large databases: 64 GB or more. Other factors to consider include database version, memory optimization options, virtualization, and best practices (monitor memory usage, adjust allocations).

iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos iOS 18 adds a new 'Recovered' album function to retrieve lost or damaged photos Jul 18, 2024 am 05:48 AM

Apple's latest releases of iOS18, iPadOS18 and macOS Sequoia systems have added an important feature to the Photos application, designed to help users easily recover photos and videos lost or damaged due to various reasons. The new feature introduces an album called "Recovered" in the Tools section of the Photos app that will automatically appear when a user has pictures or videos on their device that are not part of their photo library. The emergence of the "Recovered" album provides a solution for photos and videos lost due to database corruption, the camera application not saving to the photo library correctly, or a third-party application managing the photo library. Users only need a few simple steps

Detailed tutorial on establishing a database connection using MySQLi in PHP Detailed tutorial on establishing a database connection using MySQLi in PHP Jun 04, 2024 pm 01:42 PM

How to use MySQLi to establish a database connection in PHP: Include MySQLi extension (require_once) Create connection function (functionconnect_to_db) Call connection function ($conn=connect_to_db()) Execute query ($result=$conn->query()) Close connection ( $conn->close())

How to handle database connection errors in PHP How to handle database connection errors in PHP Jun 05, 2024 pm 02:16 PM

To handle database connection errors in PHP, you can use the following steps: Use mysqli_connect_errno() to obtain the error code. Use mysqli_connect_error() to get the error message. By capturing and logging these error messages, database connection issues can be easily identified and resolved, ensuring the smooth running of your application.

How to start the listening program in oracle How to start the listening program in oracle May 10, 2024 am 03:12 AM

Oracle listeners are used to manage client connection requests. Startup steps include: Log in to the Oracle instance. Find the listener configuration. Use the lsnrctl start command to start the listener. Use the lsnrctl status command to verify startup.

See all articles