易截截图软件、单文件、免安装、纯绿色、仅160KB

程序开发: Oracle各种日期计算方法(收藏)

一个月的第一天
代码 (双击代码复制到粘贴板)
SELECT to_date(to_char(SYSDATE,'yyyy-mm')||'-01','yyyy-mm-dd')
from dual

sysdate 为数据库服务器的当前系统时间。
to_char 是将日期型转为字符型的函数。
to_date 是将字符型转为日期型的函数,一般使用 yyyy-mm-dd hh24:mi:ss格式,当没有指定时间部分时,则默认时间为 00:00:00
dual 表为sys用户的表,这个表仅有一条记录,可以用于计算一些表达式,如果有好事者用 sys 用户登录系统,然后在 dual 表增加了记录的话,那么系统99.999%不能使用了。为什么使用的时候不用 sys.dual 格式呢,因为 sys 已经为 dual 表建立了所有用户均可使用的别名。
一年的第一天
代码 (双击代码复制到粘贴板)
SELECT to_date(
to_char(SYSDATE,'yyyy')||'-01-01','yyyy-mm-dd'
)
from dual

季度的第一天
代码 (双击代码复制到粘贴板)
SELECT to_date(
to_char(SYSDATE,'yyyy-')||
lpad(floor(to_number(to_char(SYSDATE,'mm'))/3)*3+1,2,'0')||
'-01',
'yyyy-mm-dd')
from dual

floor 为向下取整
lpad 为向左使用指定的字符扩充字符串,这个扩充字符串至2位,不足的补'0'。
当天的半夜
SELECT trunc(SYSDATE)+1-1/24/60/60
from dual
trunc 是将 sysdate 的时间部分截掉,即时间部分变成 00:00:00
Oracle中日期加减是按照天数进行的,所以 +1-1/24/60/60 使时间部分变成了 23:59:59。
Oracle 8i 中仅支持时间到秒,9i以上则支持到 1/100000000 秒。
上个月的最后一天
代码 (双击代码复制到粘贴板)
SELECT trunc(last_day(add_months(SYSDATE,-1)))+1-1/24/60/60
from dual

add_months 是月份加减函数。
last_day 是求该月份的最后一天的函数。
本年的最后一天
代码 (双击代码复制到粘贴板)
SELECT trunc(
last_day(to_date(to_char(SYSDATE,'yyyy')||'-12-01','yyyy-mm-dd'))
)+1-1/24/60/60
from dual

本月的最后一天
代码 (双击代码复制到粘贴板)
select trunc(last_day(sysdate))+1-1/24/60/60
from dual

本月的第一个星期一
代码 (双击代码复制到粘贴板)
SELECT next_day(
to_date(to_char(SYSDATE,'yyyy-mm')||'-01','yyyy-mm-dd'),
'星期一'
)


相关文档:

Oracle 10g RAC On Linux Using NFS

http://inthirties.com:90/thread-918-3-1.html
This article describes the installation of
Oracle 10g release 2 (10.2.0.1) RAC on Linux (Oracle Enterprise Linux
4.5) using NFS to provide the shared storage.
Introduction
Download Software
Operating System Installation
Oracle Installation Prereq ......

oracle数据库

关键字: oracle数据库
Oracle数据库命令集
1、sqlplus启动方式:
Dos下运行sqlplus 用户名/密码  as sysdba
例如:c:>sqlplus sys/password AS sydba(系统帐户)
或者:c:>sqlplus scott/password
2、用户连接(切换)操作:
sql>conn Scott/password(默认为tiger)
注:conn与connect使用方法一 ......

ORACLE:主键索引更换表空间

        在 Oracle 中,对于已经建好的主键,是自动创建索引的,并且索引是创建到当前的表空间中的,如果要将索引更换到其它表空间,可以使用如下的方法,超简单:
   alter index index_aaa rebuild tablespace newtablespace;
newtablespace 是新指定的表空间。 ......

Red Hat Cluster Suite集群 Oracle数据库


目录
一、概述
二、硬件平台搭建
三、Redhat As4 update2安装配置
四、Oracle 10g安装配置
五、Red Hat Cluster Suite安装配置
六、系统切换测试
七、常用命令
一、概述
黄岛市开发区财政局本次采用两台IBM X3850-8664服务
器、
一台DS4300盘阵,平台采用Redhat As4 update2 结合cluster suite,部署Oracle ......

Oracle Date Function 讲解和事例

http://blog.csdn.net/mustbelove/archive/2007/04/17/1567836.aspx(转)
1 year=1*12 months
1 day=24
hours=24*(1*60mins)=24*60*(1*60 seconds)
1 week =7 days
注意:
黑色字体是 oracle

8i,9i都可以使用的函数,
蓝色字体是 Oracle
9i

增的部分。
 
请大家在使用时,注意版本限制。
add_mon ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号