使用物化视图就可以了,比如:
create materialized view mv_test
refresh complete
as --子查询语句,同普通view一样
select emp.empno,emp.ename,emp.job,emp.hiredate,emp.comm,dept.loc
from emp,dept
where emp.deptno=dept.deptno
土嘎嘎的粉丝们大家好!
直接使用date类型就可以,该类型精确到秒
如果字符串转日期使用to_date函数
如
如果对你有帮助,望采纳.
oracle中没有datetime类型的字段,只有date类型,可以参考以下语句:
create?table?test
(id?int,
time?date?default?sysdate);
其中default sysdate就是代表默认的系统时间,验证方法如下:
insert?into?test?(id)?values?(1);
commit;
结果截图:
插入的时间与系统时间是一致的,说明设置默认时间是成功的.
你参考的例子是MS Sql Server的,@XX是变量的意思.我改写了一下,因为oracle没有identity自增,所以用了sequence.
首先建表:
CREATE TABLE time_by_day_dimension(
time_id int NOT NULL ,
the_date date NULL ,
the_year smallint NULL ,
day_of_month smallint NULL ,
week_of_year smallint NULL ,
month_of_year smallint NULL ,
);
然后是创建序列:
create sequence seq_time_id start with 1 increment by 1 nocycle nocache ;
最后是过程:
create or replace
PROCEDURE Create_time_by_day_dimension
IS
dDate DATE;
iYear smallint;
iDayOfMonth smallint;
iWeekOfYear smallint;
iMonthOfYear smallint;
adddays int;
BEGIN
adddays := 1 ;
loop
WeekString := to_char(dDate, 'day'); --星期几
sMonth:=to_char(dDate, 'mm');--月份
iYear:= to_char(dDate, 'yyyy');--年
iDayOfMonth:=to_char(dDate, 'dd');--日(字符型)
iWeekOfYear:= to_char(dDate,'fmww');--年的第几周
iMonthOfYear:=to_number(sMonth);--日(数字型)
INSERT INTO time_by_day_dimension(time_id,the_date, the_day, the_month, the_year, day_of_month, week_of_year, month_of_year)
VALUES (seq_time_id.nextval,dDate, WeekString, sMonth, iYear, iDayOfMonth, iWeekOfYear, iMonthOfYear);
dDate := dDate + adddays;
END loop;
end;
最后少了一个字段:季度.你再学习添加一下吧!
以上就是土嘎嘎小编为大家整理的oracle如何创建时间相关主题介绍,如果您觉得小编更新的文章只要能对粉丝们有用,就是我们最大的鼓励和动力,不要忘记讲本站分享给您身边的朋友哦!!