0
create table CIT_ADMIN.OBJECT_DETAIL_MASTER (
  RULE_ID   VARCHAR(10), 
  ATTR_1   VARCHAR(50), 
  ATTR_2   VARCHAR(50), 
  ATTR_3   VARCHAR(50), 
  CREATED_DATE    DATE DEFAULT SYSDATE)

create table CIT_ADMIN.PRIORITY_RULE_FACTORY (
  RULE_ID   VARCHAR(10), 
  RULE_DESC VARCHAR(10), 
  RULE_1   VARCHAR(50), 
  RULE_2   VARCHAR(50), 
  RULE_3   VARCHAR(50), 
  CREATED_DATE    DATE DEFAULT SYSDATE)

insert into CIT_ADMIN.PRIORITY_RULE_FACTORY
       (RULE_ID, RULE_DESC,  RULE_1,         RULE_2,          RULE_3)
values ('1',     'POSITION', 'ODS_KEY',      'NOTIONAL',      'SIK')

insert into CIT_ADMIN.PRIORITY_RULE_FACTORY
       (RULE_ID, RULE_DESC,  RULE_1,         RULE_2,          RULE_3)
values ('2',     'CLIENT',   'UCN',          'AGREEMENT_ID',  'FACILITY_ID')

insert into CIT_ADMIN.PRIORITY_RULE_FACTORY
       (RULE_ID, RULE_DESC,  RULE_1,         RULE_2,          RULE_3)
values ('3',     'NETTING',  'AGREEMENT_ID', 'AGREEMENT_AMT', 'MATURITY')

insert into CIT_ADMIN.OBJECT_DETAIL_MASTER
       (RULE_ID, ATTR_1, ATTR_2, ATTR_3)
values ('1',     '123',  '1000', '600')

insert into CIT_ADMIN.OBJECT_DETAIL_MASTER
       (RULE_ID, ATTR_1, ATTR_2, ATTR_3)
values ('2',     '456',  '2000', '500')

insert into CIT_ADMIN.OBJECT_DETAIL_MASTER
       (RULE_ID, ATTR_1, ATTR_2, ATTR_3)
values ('3',     '789',  '3000', '400')

These are my tables. Rule id is foreign key in master table, also the primary key in rule factory table. I tried writing query that can link the rule with the data.

**Like:**
WITH ATTR AS (SELECT * FROM CIT_ADMIN.PRIORITY_RULE_FACTORY WHERE RULE_DESC = 'POSITION')

SELECT ATTR_2 FROM CIT_ADMIN.OBJECT_DETAIL_MASTER a
WHERE RULE_ID in (SELECT ATTR.RULE_ID FROM attr) 
AND ATTR_1 = '123'

If I know position and ods_key I want Notional. This query fetched me that but the problem is i dont know the position of those attributes. Can you guys please give me some pointers to move ahead.!!!

Regards.

4

2 回答 2

1

我认为这是一个非常复杂的设计。我的意思是,当臭名昭著的 EAV 模式看起来像是一个明智的选择时,模型肯定有问题。

无论如何,这里有一个函数可以解决手头的任务:我建议一个函数仅仅是因为规则引擎是棘手的野兽,而在修改你的功能时,封装会很好地为你服务。

create or replace function eval_rule
    ( p_rule_id in priority_rule_factory.rule_id%type
      , p_rule in priority_rule_factory.rule_1%type )
     return object_detail_master.attr_1%type
is
    return_value object_detail_master.attr_1%type;
begin

     select case 
            when prf.rule_1 = p_rule then odm.attr_1
            when prf.rule_2 = p_rule then odm.attr_2
            when prf.rule_3 = p_rule then odm.attr_3
            end
    into return_value
    from priority_rule_factory prf
         join object_detail_master odm
            on prf.rule_id = odm.rule_id
    where prf.rule_id = p_rule_id;        

    return return_value;
end eval_rule;
/
于 2013-08-01T17:41:42.220 回答
1

如果您将“规则”和“属性”标准化 - 创建一个包含单个属性名称(例如“ODS_KEY”、“NOTIONAL”等)和随之而来的值(例如123、1000 等)并将其与规则相关联(例如“位置”、“客户”、“网络”等)。

分享和享受。

于 2013-07-23T14:08:37.623 回答