第一次操作多张相关联的数据库表,傻傻的去做一张一张的操作。结果发现写sql语句去Low数据,发现怎么都Low不出来。事后(也就是现在,我先笑一笑)
向6张表里插入数据:
insert into DE_CONTRACT_INFO (id,RECORD_TYPE,ID_DE_RULE_CHECK_REQ,CDATE,EDATE,CREATOR,EDITOR,STATUS) values(1,1,1,sysdate,sysdate,'pd','pd1','a');
insert into de_external_ds (id,ID_DE_RULE_CHECK_REQ,CDATE,EDATE,CREATOR,EDITOR,STATUS)values(1,1,sysdate,sysdate,'pd','pd1','a');
insert into DE_HARD_CHECK (ID,ID_DE_RULE_CHECK_REQ,CDATE,EDATE,CREATOR,EDITOR,STATUS)values(1,1,sysdate,sysdate,'pd','pd1','a');
insert into DE_ONLINE_TRIGGERS(ID,ID_DE_RULE_CHECK_REQ,STATUS)values(1,1,'a');
insert into DE_ROUND (ID,ID_DE_RULE_CHECK_REQ,ROUND,RAND1,RAND2,RAND3,CDATE,EDATE,CREATOR,EDITOR,STATUS)values(1,1,1,1.1,1,1,sysdate,sysdate,'pd','pd1','a');
insert into DE_ROUND_RESULT(ID,ID_DE_ROUND,CDATE,EDATE,CREATOR,EDITOR,STATUS)values(1,1,sysdate,sysdate,'pd','pd1','a');
insert into DE_RULE_CHECK_RESULT (ID,ID_DE_RULE_CHECK_REQ,CDATE,EDATE,CREATOR,EDITOR,STATUS) values(1,1,sysdate,sysdate,'pd','pd1','a');
insert into De_Rule_Check_Req(ID,ID_DE_RULE_CHECK_REQ,CDATE,EDATE,CREATOR,EDITOR,STATUS)values(12,1,sysdate,sysdate,'pd','pd1','a');
insert into de_round_result (ID,ID_DE_ROUND) values(1,11);
查询6张表关联后的结果:
select r.ID
from de_rule_check_req rcr
left join DE_CONTRACT_INFO ci1
on (rcr.ID = ci1.ID_DE_RULE_CHECK_REQ and ci1.RECORD_TYPE = '1')
left join DE_CONTRACT_INFO ci2
on (rcr.ID = ci2.ID_DE_RULE_CHECK_REQ and ci2.RECORD_TYPE = '2')
left join DE_HARD_CHECK hc
on (hc.ID_DE_RULE_CHECK_REQ = rcr.ID)
left join DE_ONLINE_TRIGGERS ot
on (ot.ID_DE_RULE_CHECK_REQ = rcr.ID)
left join DE_EXTERNAL_DS ed
on (ed.ID_DE_RULE_CHECK_REQ = rcr.id)
left join DE_WORKFLOW_ACT wa
on (wa.ID_DE_RULE_CHECK_REQ = rcr.id)
left join DE_ROUND r
on (r.ID_DE_RULE_CHECK_REQ = rcr.ID and r.ROUND = 1)
left join (select rr1.*, d.ID_DE_RULE_CHECK_REQ id_rcr, d.id id_last_round
from de_round d, de_round_result rr1
where d.ID = rr1.ID_DE_ROUND(+)
and d.ROUND = 1 - 1) aa
on (aa.id_rcr = rcr.id)
where rcr.id_application = 504;
查询通过de之后返回的结果。
select * from de_round_result where id_de_round=503;
怎么都查不出来,结果就是,去问数据库工程师,说是要关联的插入数据才能够查出一张综合的表出来。逻辑嘛,很麻烦。现在暂时还不太了解,是用了存储过程。。。