CREATE OR REPLACE TRIGGER TRG_KC_SPRK_i
BEFORE INSERT ON KC_SPRK
FOR EACH ROW
DECLARE
vSCBH varchar2(40);
iCount NUMBER;
iFor number;
BEGIN
select t.bhqz into vSCBH from xt_djbhgz t where t.gzid=8;--这里是获取另一张表的某一个字段作为前缀,或者直接赋值也行: vSCBH := ‘GXCB_’
select count(1)+1 INTO iCount from KC_SPRK j where j.xzsj>=trunc(sysdate,'mm'); --这里是获取本张表的总数 + 1,并赋值给iCount
vSCBH:=vSCBH||to_char(sysdate,'yyyymm'); --这里是前缀+时间年月
FOR iFor IN 1..5-LENGTH(iCount) LOOP
vSCBH:=vSCBH||'0';
END LOOP;
:new.RK_DJH:=vSCBH||iCount;

END TRG_KC_SPRK_i;

效果:GXCB_20141100001 GXCB_20141100002 GXCB_20141100003