oracle数据表我是按某一列进行列表分区,然后我想实现插入一条数据进行判断,如果新插入的数据的该列没有表分区,就进行自动添加表分区,然后插入进去,如果有了就直接插入该表分区。用plsql触发器实现。我自己写了代码但是无法实现。我把它贴出来,如果能再原程序上修改最好,如果我的思路都错了,能写一个就谢谢了您了。我是刚进入这一行,越详细越好,谢谢各位前辈了!代码如下:
create or replace trigger tg_tbinfo
before insert on tbinfo for each row
declare
v_pd number:=1;
v_tid Tbinfo.Tid%type;
type sp_coure is ref cursor;
sp_tbinfo_coursor sp_coure;
begin
open sp_tbinfo_coursor for select tid from Tbinfo ;
loop
fetch sp_tbinfo_coursor into v_tid;
exit when sp_tbinfo_coursor%notfound;
if v_tid <> :new.tid then
v_pd:=0;
else
v_pd :=1;
end if;
end loop;
if v_pd=0 then
execute immediate'alter table tbinfo add partition sp_5 values(&new.tid);';
end if;
close sp_tbinfo_coursor;
end;
create or replace trigger tg_tbinfo
before insert on tbinfo for each row
declare
v_pd number:=1;
v_tid Tbinfo.Tid%type;
type sp_coure is ref cursor;
sp_tbinfo_coursor sp_coure;
begin
open sp_tbinfo_coursor for select tid from Tbinfo ;
loop
fetch sp_tbinfo_coursor into v_tid;
exit when sp_tbinfo_coursor%notfound;
if v_tid <> :new.tid then
v_pd:=0;
else
v_pd :=1;
end if;
end loop;
if v_pd=0 then
execute immediate'alter table tbinfo add partition sp_5 values(&new.tid);';
end if;
close sp_tbinfo_coursor;
end;
第一次见到这样的list分区。
还有hash 和 range了你知道吗?
你这个如果不能确认范围的话,可以用hash分区。
第一:数据量要够大,几万条我不建议做分区
第二:分区的方法很多,例如段分区、固定值分区、hash分区等等
段分区:可以按照年份、月份甚至日期创建分区
固定值分区:例如业绩考评我们可以用A、B、C、D作为分区的条件等等
第三:现有的索引也要考虑
第四:就是程序的变动,不需与分区协调