[英]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'));
I have this view, where I get 2 months before data from employee table on 5th day of every month. 我有这种观点,在每个月的第5天,我从employee表中获得数据之前2个月。
How can I use the same view to get last month's data like below from 10th day of every month. 我如何使用同一视图从每个月的第10天获取上个月的数据,如下所示。
create or replace view as
(select emp,department,salary
from employee
where partition_key = to_char(add_months(sysdate,-1) 'yyyymm'));
From comments: 来自评论:
Basically, for the first 10 days of a month, I want to see 2 months before data and from 10th night, I want to see last month data. 基本上,对于一个月的前10天,我想查看数据之前的2个月,而从10日晚上开始,我想查看上个月的数据。
Given your updated requirements it appears that the following will accomplish what you want: 考虑到您更新的要求,看来以下将完成您想要的:
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');
Best of luck. 祝你好运。
It seems like you could subtract 10 days from the current date ... 看来您可以从当前日期减去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.