[英]How can I create oracle view to be dynamic?
create or replace view as
(select emp,department,salary
from employee
where partition_key = to_char(add_months(sysdate,-2) 'yyyymm'));
我有这种观点,在每个月的第5天,我从employee表中获得数据之前2个月。
我如何使用同一视图从每个月的第10天获取上个月的数据,如下所示。
create or replace view as
(select emp,department,salary
from employee
where partition_key = to_char(add_months(sysdate,-1) 'yyyymm'));
来自评论:
基本上,对于一个月的前10天,我想查看数据之前的2个月,而从10日晚上开始,我想查看上个月的数据。
考虑到您更新的要求,看来以下将完成您想要的:
create or replace view as
select emp, department, salary
from employee
where partition_key =
to_char(add_months(sysdate,
CASE
WHEN TO_NUMBER(TRIM(TO_CHAR(SYSDATE, 'DD'))) <= 10
THEN -2
ELSE -1
END), 'yyyymm');
祝你好运。
看来您可以从当前日期减去10天...
create or replace view blah
as
select
emp,
department,
salary
from
employee
where
partition_key = to_char(add_months(trunc(sysdate-10,'mm'),-1) 'yyyymm'));
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.