按照你現有的表建立歷史資料:
create table khqfbd_1
(khn int,
khqxh int,
khmc varchar2(20),
qsrq varchar2(8),
jsrq varchar2(8),
bz varchar2(100));
insert into khqfbd_1 values (2024,1,"第一季度","20240101","20240331","1");
insert into khqfbd_1 values (2024,2,"第二季度","20240401","20240630","1");
insert into khqfbd_1 values (2024,3,"第三季度","20240701","20240930","1");
insert into khqfbd_1 values (2024,4,"第四季度","20241001","20241231","1");
commit;
執行:
declare
v_year int;
begin
select max(khn) into v_year from khqfbd_1;
insert into khqfbd_1
values
(v_year+1, 1, "第一季度", v_year+1 || "0101", v_year+1 || "0331", "1");
(v_year+1, 2, "第二季度", v_year+1 || "0401", v_year+1 || "0630", "1");
(v_year+1, 3, "第三季度", v_year+1 || "0701", v_year+1 || "0930", "1");
(v_year+1, 4, "第四季度", v_year+1 || "1001", v_year+1 || "1231", "1");
end;
執行後結果:
按照你現有的表建立歷史資料:
create table khqfbd_1
(khn int,
khqxh int,
khmc varchar2(20),
qsrq varchar2(8),
jsrq varchar2(8),
bz varchar2(100));
insert into khqfbd_1 values (2024,1,"第一季度","20240101","20240331","1");
insert into khqfbd_1 values (2024,2,"第二季度","20240401","20240630","1");
insert into khqfbd_1 values (2024,3,"第三季度","20240701","20240930","1");
insert into khqfbd_1 values (2024,4,"第四季度","20241001","20241231","1");
commit;
執行:
declare
v_year int;
begin
select max(khn) into v_year from khqfbd_1;
insert into khqfbd_1
values
(v_year+1, 1, "第一季度", v_year+1 || "0101", v_year+1 || "0331", "1");
insert into khqfbd_1
values
(v_year+1, 2, "第二季度", v_year+1 || "0401", v_year+1 || "0630", "1");
insert into khqfbd_1
values
(v_year+1, 3, "第三季度", v_year+1 || "0701", v_year+1 || "0930", "1");
insert into khqfbd_1
values
(v_year+1, 4, "第四季度", v_year+1 || "1001", v_year+1 || "1231", "1");
commit;
end;
執行後結果: