我有一个物化视图表,其中包含有关员工及其对系统的访问的信息,该表有一个“有效日期”列和“有效日期”列。这个物化视图每晚更新一次。
我想在此表中添加一个额外的列“current_flag”,以显示当前员工是否具有“Y”或“N”的访问权限。我正在考虑使用类似以下的“案例”声明:-
CASE WHEN to_date(c.effective_date) < to_date(sysdate)
and to_date (effective_date_to) > to_date(sysdate)
THEN 'Y'
ELSE 'N'
END) AS current_flag
这是最好的方法吗?如果是,正确的语法是什么,因为我正在努力让它工作..
原始物化视图表如下...
CREATE MATERIALIZED VIEW TC.employee_access
(
EMPL_ID,
EFFECTIVE_DATE,
EFFECTIVE_DATE_TO,
DEPARTMENT,
JOB_DESCRIPTION,
TIME_STAMP,
MODIFIED_BY
)
TABLESPACE TC_TC_DATA
PCTUSED 0
PCTFREE 10
INITRANS 2
MAXTRANS 255
STORAGE (
INITIAL 64K
NEXT 1M
MINEXTENTS 1
MAXEXTENTS UNLIMITED
PCTINCREASE 0
BUFFER_POOL DEFAULT
)
NOCACHE
LOGGING
NOCOMPRESS
NOPARALLEL
BUILD IMMEDIATE
REFRESH FORCE
START WITH TO_DATE('16-Jan-2013','dd-mon-yyyy')
NEXT TRUNC(SYSDATE+1)
WITH PRIMARY KEY
AS
SELECT C.EMPL_ID AS Empl_Id,
C.EFFECTIVE_DT AS Effective_Date,
DECODE (n.effective_dt,
c.effective_dt, TO_DATE ('01/01/2099', 'DD/MM/YYYY'),
n.effective_dt - 1)
AS Effective_Date_To,
C.DFLT_UDT06_ID AS Department,
C.DFLT_UDT08_ID AS Job_Description,
C.TIME_STAMP,
C.MODIFIED_BY
FROM empl_history_mv c, empl_history_mv n
WHERE n.effective_dt =
(SELECT NVL (MIN (effective_dt), c.effective_dt)
FROM empl_history_mv
WHERE empl_id = c.empl_id AND effective_dt > c.effective_dt)
AND c.empl_id = n.empl_id;