Oracle中比例和时间二者需兼得
在Oracle中,按照SQL 99标准,增加了时间间隔型数据INTERVAL YEAR TO MONTH 和 INTERVAL DAY TO SECOND,它们和其他几种数据类型
在监控、诊断、处理数据库性能问题的时候,,时间信息往往是非常重要的判断依据。有时候可能我们会使用一些比例来判断性能,但是使用比例而不使用时间往往会将我们带向错误的方向。
在以前的版本中,Oracle的时间计量单位是厘秒,使用厘秒最显而易见的问题就是可能有些操作是小于厘秒的。看上去这似乎不太常见,但是实际上在操作系统上很多操作都是以微妙作为单位的,这意味着操作的起始和终止在不到厘秒就完成了,从厘秒级看就好像没有发生一样,因为持续时间近似为0。而有时候操作的持续时间不到厘秒,但是起始和终止发生在两个相连的厘秒,所以操作时间不到厘秒但是却被记录为厘秒,造成时间记录的不准确。Oracle 没有内置的方式来记录时间的流逝。DATE型数据用来记录单独的时间点;但是要表达一个时间量(也就是一个间隔),数据库的设计者就必须把时间间隔转换成原始单位秒,然后用一个NUMBER列来保存它。
虽然NUMBER这个数据类型可以以秒为单位准确地表示时间,但是它使得时间的计算变得很困难。比如,60秒是1分钟,60分钟是1个小时,24个小时等于1天——这些数字在以十进制为基础的数字系统中都是非常不实用的。
在Oracle中,按照SQL 99标准,增加了时间间隔型数据INTERVAL YEAR TO MONTH 和 INTERVAL DAY TO SECOND,它们和其他几种数据类型一起使得对时间的处理更加准确。TIMESTAMP、TIMESTAMP WITH TIME ZONE和TIMESTAMP WITH LOCAL TIME ZONE等数据类型都把时间的表达精确到了若干分之一秒,而且后面两种还解决了地理位置造成的时间变化。
Sql语句的等待时间等于ELAPSED_TIME减去CPU_TIME,但是很难看到精确的等待时间。在V$SYSTEM_EVENT 视图中能够看到数据库实例级的等待时间(并不是每条Sql语句的),但是看不到发生在操作系统上的等待时间。
在SQL和PL/SQL中,你都可以用时间间隔型数据,它们都是用同一种方式规定的:
INTERVAL YEAR[(year_precision)] TO MONTH
INTERVAL DAY[(day_precision)] TO SECOND[(fractional_seconds_precision)]
转换函数,与date操作关系最大的就是两个转换函数:to_date(),to_char()
to_date() 作用将字符类型按一定格式转化为日期类型:
具体用法:to_date('2008-11-27','yyyy-mm-dd'),前者为字符串,后者为转换日期格式,注意,前后两者要以一对应。
如;to_date('2008-11-27 13:34:43', 'yyyy-mm-dd hh24:mi:ss') 将得到具体的时间
对于精确数值,规定有缺省值:年和日是两位数,若干分之一秒是六位数。
时间间隔的大小由INTERVAL来表示,后面紧接一个放在单引号中的表达式,以及用来解释该表达式的文字。用YEAR TO MONTH表示时间间隔大小时要在年和月之间用一个连字符(-) 连接。而DAY TO SECOND表示时间间隔大小时要在日和时间之间用一个空格连接。例子如下:
返回当前时间 年月日小时分秒毫秒
select to_char(current_timestamp(5),'DD-MON-YYYY HH24:MI:SSxFF') from dual;
返回当前 时间的秒毫秒,可以指定秒后面的精度(最大=9)
select to_char(current_timestamp(9),'MI:SSxFF') from dual;
实现最大值与当前时间的比较
通过对记录中最大的时间加上指定月份得到范围上限,并用CURRENT_DATE获取当前系统时间与之比较,如果超出该上限则判断为不存在,表示为0,否则表示为1。
SQL:
SELECT COUNT(*) contains
FROM DUAL t
WHERE CURRENT_DATE
FROM red_meettingrecord t
WHERE t.med_tar_id = '225'
AND t.med_usr_id = '001387')
通过对记录中最大的时间加上指定月份得到范围上限,并用CURRENT_DATE获取当前系统时间与之比较,如果超出该上限则判断为不存在,表示为0,否则表示为1。

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics











MySQL is an open source relational database management system, mainly used to store and retrieve data quickly and reliably. Its working principle includes client requests, query resolution, execution of queries and return results. Examples of usage include creating tables, inserting and querying data, and advanced features such as JOIN operations. Common errors involve SQL syntax, data types, and permissions, and optimization suggestions include the use of indexes, optimized queries, and partitioning of tables.

In Oracle, the FOR LOOP loop can create cursors dynamically. The steps are: 1. Define the cursor type; 2. Create the loop; 3. Create the cursor dynamically; 4. Execute the cursor; 5. Close the cursor. Example: A cursor can be created cycle-by-circuit to display the names and salaries of the top 10 employees.

MySQL is chosen for its performance, reliability, ease of use, and community support. 1.MySQL provides efficient data storage and retrieval functions, supporting multiple data types and advanced query operations. 2. Adopt client-server architecture and multiple storage engines to support transaction and query optimization. 3. Easy to use, supports a variety of operating systems and programming languages. 4. Have strong community support and provide rich resources and solutions.

Building a Hadoop Distributed File System (HDFS) on a CentOS system requires multiple steps. This article provides a brief configuration guide. 1. Prepare to install JDK in the early stage: Install JavaDevelopmentKit (JDK) on all nodes, and the version must be compatible with Hadoop. The installation package can be downloaded from the Oracle official website. Environment variable configuration: Edit /etc/profile file, set Java and Hadoop environment variables, so that the system can find the installation path of JDK and Hadoop. 2. Security configuration: SSH password-free login to generate SSH key: Use the ssh-keygen command on each node

When Oracle log files are full, the following solutions can be adopted: 1) Clean old log files; 2) Increase the log file size; 3) Increase the log file group; 4) Set up automatic log management; 5) Reinitialize the database. Before implementing any solution, it is recommended to back up the database to prevent data loss.

Oracle is not only a database company, but also a leader in cloud computing and ERP systems. 1. Oracle provides comprehensive solutions from database to cloud services and ERP systems. 2. OracleCloud challenges AWS and Azure, providing IaaS, PaaS and SaaS services. 3. Oracle's ERP systems such as E-BusinessSuite and FusionApplications help enterprises optimize operations.

MySQL is suitable for web applications and content management systems and is popular for its open source, high performance and ease of use. 1) Compared with PostgreSQL, MySQL performs better in simple queries and high concurrent read operations. 2) Compared with Oracle, MySQL is more popular among small and medium-sized enterprises because of its open source and low cost. 3) Compared with Microsoft SQL Server, MySQL is more suitable for cross-platform applications. 4) Unlike MongoDB, MySQL is more suitable for structured data and transaction processing.

Oracle views can be exported through the EXP utility: Log in to the Oracle database. Start the EXP utility, specifying the view name and export directory. Enter export parameters, including target mode, file format, and tablespace. Start exporting. Verify the export using the impdp utility.
