解决方案 »
- Oricle安装问题 急
- 请教ORACLE 数据库控制日志问题?
- 请问如何执行数据库链路上的过程?急
- 准备学习oracle了,散点分,也想听听前辈的经验
- 求一个事务的写法
- 菜鸟问题:如果显示ORACLE中表中的数据啊,有没有不用SQLPLUS的方法直接以表格的形式显示出来的。
- 跪求ORACLE时间比较的SQL语句------在线急等!!!!!
- 请教:ORACLE是如何打开数据库的?
- 用了我最后的84分!请高手进来看看吧!关于blob存储过程插入!万分感谢!!!
- 求救:为什么我在redhat linux7.3下装的oracle8.1.7.0.0不能输入
- oracle 10g 触发器中时间相减问题
- 安装oem12报错
SQL> select trunc(extract(day from dt2-dt1)/365,1)
2 from (
3 select to_timestamp('2008-12-10','yyyy-mm-dd hh24:mi:ss') dt1,
4 to_timestamp('2011-11-10 18:54:25','yyyy-mm-dd hh24:mi:ss') dt2
5 from dual)
6 /
TRUNC(EXTRACT(DAYFROMDT2-DT1)/
------------------------------
2.9
MOD(months_between(a,b),12) AS 月
FROM
(
SELECT trunc(to_date('2011-11-10 18:54:25','yyyy-mm-dd hh24:mi:ss'),'mm')a,
trunc(to_date('2008-12-10','yyyy-mm-dd'),'mm') b
FROM dual
)
SELECT replace(trunc(months_between(a,b)/12,1),'.','年')||'月'
FROM
(
SELECT trunc(to_date('2011-11-10 18:54:25','yyyy-mm-dd hh24:mi:ss'),'mm')a,
trunc(to_date('2008-12-10','yyyy-mm-dd'),'mm') b
FROM dual
)--result:
2年9月
那如何把他加到 触发器里
create or replace trigger insert_out_user
after delete on employee
for each row
declare
v_num number;
begin select count(*) into v_num from out_employee; insert into out_employee
values
(
v_num + 1,
:old.u_name,
:old.u_entry_time,
sysdate,
select trunc(extract(day from dt2 - dt1) / 365, 1)
from
(
select to_timestamp(:old.u_entry_time, 'yyyy-mm-dd hh24:mi:ss') dt1,
to_timestamp(sysdate, 'yyyy-mm-dd hh24:mi:ss') dt2
from dual),
:old.u_department,
:old.u_post,
:old.u_sex,
:old.u_age,
:old.u_phone
); end insert_out_user;
SELECT replace(trunc(months_between(a,b)/12,1),'.','年')||'月'
FROM
(
SELECT trunc(to_date('2011-11-10 18:54:25','yyyy-mm-dd hh24:mi:ss'),'mm')a,
trunc(to_date('2008-12-10','yyyy-mm-dd'),'mm') b
FROM dual
)
create or replace trigger insert_out_user
after delete on employee
for each row
declare
v_num number;
begin select count(*) into v_num from out_employee; insert into out_employee
values
(
v_num + 1,
:old.u_name,
:old.u_entry_time,
sysdate,
select trunc(extract(day from dt2 - dt1) / 365, 1)
from
(
select to_timestamp(:old.u_entry_time, 'yyyy-mm-dd hh24:mi:ss') dt1,
to_timestamp(sysdate, 'yyyy-mm-dd hh24:mi:ss') dt2
from dual),
:old.u_department,
:old.u_post,
:old.u_sex,
:old.u_age,
:old.u_phone
); end insert_out_user;
to_date('2008-12-10', 'yyyy-mm-dd')))/12, 1) as months from dual;