扫二维码与项目经理沟通
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流
我感觉你应该是不知道怎么写每月和每年吧。其实很简单,把你下次时间的字符串拿出来看下就行。下面是代码。
站在用户的角度思考问题,与客户深入沟通,找到青海网站设计与青海网站推广的解决方案,凭借多年的经验,让设计与互联网技术结合,创造个性化、用户体验好的作品,建站类型包括:成都网站制作、网站设计、企业官网、英文网站、手机端网站、网站推广、域名注册、网站空间、企业邮箱。业务覆盖青海地区。
DECLARE
I4 INTEGER;I5 INTEGER;
BEGIN
--每月5号中午12点
DBMS_JOB.SUBMIT(I4,'YOUR PROC;',SYSDATE,'TRUNC(SYSDATE, ''MM'') + 4 + 12 / 24');
--每年1月10号中午12点
DBMS_JOB.SUBMIT(I5,'YOUR PROC;',SYSDATE,'TRUNC(SYSDATE, 'Y') + 9 + 12 / 24');
COMMIT;
END;
第一步:创建表
--支出表
create table PAY
(
ID NUMBER(11) not null,
PAY_NAME VARCHAR2(100),
AUTHOR VARCHAR2(100),
TYPE_ID NUMBER(11),
PRICE FLOAT, --金额
BRIEF VARCHAR2(1000),
USERID NUMBER(11), --用户ID
TIMES DATE, --时间
PRIMARY KEY(ID)
)
第二步:插入数据
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (1, '1', '1', 0, 1, '1', 1, to_date('12-10-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (0, '3', '3', 1, 3, '3', 1, to_date('12-10-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (2, '2', '2', 1, 2, '2343444', 1, to_date('12-10-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (6, '6', '1', 0, 4000, '1', 1, to_date('12-08-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (5, '5', '1', 0, 1, '1', 1, to_date('12-10-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (4, '4', '1', 0, 100, '1', 1, to_date('12-09-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (7, '4', '1', 0, 566, '1', 1, to_date('03-03-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (11, '4', '1', 0, 566, '1', 1, to_date('03-04-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (10, '4', '1', 0, 566, '1', 1, to_date('03-05-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (9, '4', '1', 0, 566, '1', 1, to_date('03-06-2012', 'dd-mm-yyyy'));
insert into PAY (ID, PAY_NAME, AUTHOR, TYPE_ID, PRICE, BRIEF, USERID, TIMES)
values (8, '4', '1', 0, 566, '1', 1, to_date('03-07-2012', 'dd-mm-yyyy'));
commit;
第三步:执行分组查询
SELECT SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 1, B.PRICE, 0)) AS A,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 2, B.PRICE, 0)) AS B,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 3, B.PRICE, 0)) AS C,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 4, B.PRICE, 0)) AS D,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 5, B.PRICE, 0)) AS E,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 6, B.PRICE, 0)) AS F,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 7, B.PRICE, 0)) AS G,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 8, B.PRICE, 0)) AS H,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 9, B.PRICE, 0)) AS I,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 10, B.PRICE, 0)) AS J,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 11, B.PRICE, 0)) AS K,
SUM(DECODE(EXTRACT(MONTH FROM B.TIMES), 12, B.PRICE, 0)) AS L
FROM PAY B
WHERE USERID = 1
AND EXTRACT(YEAR FROM B.TIMES) = '2012'
第四步:输出结果
写一个存储过程放JOB里,每天24点定时跑,如果生日当天,就自动增加年龄。
begin dbms_scheduler.create_job(job_name = 'scan_table', job_type = 'STORED_PROCEDURE', job_action = 'sp_scan_table', --自定义的扫描表存储过程 start_date = to_timestamp('20150827 00:00:00', 'yyyymmdd hh24:mi:ss'), repeat_in...
用job,具体用法:
declare
n_job binary_integer;
begin
dbms_job.submit(n_job, '你要执行的东西', sysdate, TRUNC(LAST_DAY(SYSDATE))+4+2/24);
end;
-- 每月4号执行
dbms_job.submit(n_job_01,'你调的东西',sysdate,'TRUNC(LAST_DAY(SYSDATE))+4+2/24');
-- 每分钟执行一次
dbms_job.submit(n_job_01,'你调的东西',sysdate,'TRUNC(sysdate,’mi’) + 1 / (24*60)');
-- 凌晨两点执行
dbms_job.submit(n_job_01,'你调的东西',sysdate,'TRUNC(sysdate) + 1 + 2/24');
-- 每周一凌晨2点执行 周一是每周的第二天next_day(sysdate,2)同理周二是第三天,next_day(sysdate,3)
dbms_job.submit(n_job_01,'你调的东西',sysdate,'TRUNC(next_day(sysdate,2))+2/24');
-- 每月1日凌晨两点执行
dbms_job.submit(n_job_01,'你调的东西',sysdate,'TRUNC(LAST_DAY(SYSDATE))+1+2/24');
-- 每季第一天凌晨两点执行
dbms_job.submit(n_job_01,'你调的东西',sysdate,'TRUNC(ADD_MONTHS(SYSDATE,3),'Q') + 2/24');
-- 每年7月1日和1月1日凌晨2点
dbms_job.submit(n_job_01,'你调的东西',sysdate,'ADD_MONTHS(trunc(sysdate,'yyyy'),6)+2/24');
-- 每年1月1日凌晨2点执行
dbms_job.submit(n_job_01,'你调的东西',sysdate, 'Add_months(trunc(sysdate,'yyyy'), 12) +2/24');
htlx htje year
按合同类型 和年度分组
select htlx,year ,sum(htje) from table group by htlx year
我们在微信上24小时期待你的声音
解答本文疑问/技术咨询/运营咨询/技术建议/互联网交流