用的ERWin4进oracle建模的朋友请进
我出去测试的目的在ERWin4.1的逻辑模型中画了两个实体:t_main和t_detail
结构简单如下:
[CODE]
CREATE TABLE t_detail (
did INTEGER NOT NULL,
address CHAR(18) NULL,
id INTEGER NOT NULL
);
ALTER TABLE t_detail
ADD ( PRIMARY KEY (did, id) ) ;
CREATE TABLE t_main (
id INTEGER NOT NULL,
note CHAR(18) NULL
);
ALTER TABLE t_main
ADD ( PRIMARY KEY (id) ) ;
ALTER TABLE t_detail
ADD ( FOREIGN KEY (id)
REFERENCES t_main
ON DELETE CASCADE ) ;
([/CODE]
这是有one to one ,more 标识关系的两个实体
在参照完整性中,设置child insert :restrict
我设置数据库类型为8i,在正向工程时ERWin4.1自动生成下边这样一个trigger,
[CODE]
create or replace trigger tI_t_detail after INSERT on t_detail for each row
-- ERwin Builtin Sat Mar 04 00:02:26 2006
-- INSERT trigger on t_detail
declare numrows INTEGER;
begin
/* ERwin Builtin Sat Mar 04 00:02:26 2006 */
/* t_main R/1 t_detail ON CHILD INSERT RESTRICT */
/* ERWIN_RELATION:PARENT_OWNER="", PARENT_TABLE="t_main"
CHILD_OWNER="", CHILD_TABLE="t_detail"
P2C_VERB_PHRASE="R/1", C2P_VERB_PHRASE="",
FK_CONSTRAINT="R_1", FK_COLUMNS="id" */
select count(*) into numrows
from t_main
where
/* %JoinFKPK(:%New,t_main," = "," and") */
:new.id = t_main.id;
if (
/* %NotnullFK(:%New," is not null and") */
numrows = 0
)
then
raise_application_error(
-20002,
'Cannot INSERT t_detail because t_main does not exist.'
);
end if;
-- ERwin Builtin Sat Mar 04 00:02:26 2006
end;
[/CODE]
请注意,它先declare numrows INTEGER;
然后在body中
select count(*) into numrows
from t_main
where
:new.id = t_main.id;
这个trigger在oracle 8.1.7 上是能编译通过,但是执行出错,说select 这一行无法读取,
不知道是为什么
常用的select into 后大都是接表名,但是ERWin却是一个Integer类型的变量,所以oraclei执行这个trigger的时候就出错,为啥ERwin会生成这样的代码呢,具体是错在哪里,请大侠指正
问题点数:50、回复次数:2Top
1 楼silverpot(银斑蝶)回复于 2006-03-04 00:10:57 得分 0
帮帮忙啊Top
2 楼silverpot(银斑蝶)回复于 2006-03-04 17:29:29 得分 0
没有人会么?Top




