近日写了一些vew,用到了自定义funciton,都是多表连接查询,也没有优化,留个记录以备后查;
sql 代码
- -- create view report_service
- create or replace view report_service as
- select UPPER(trim(to_char(c.aidcategoryid, '0x')) ||
- trim(to_char(t.aidserviceid, '0xxx'))) ||
- RPAD(t.servicename, 40) || RPAD(b.id, 2) ||
- RPAD(decode(y.id, 1, 3, 2, 2, 3, 1) || l.userlevelid, 5) || '1' ||
- RPAD(' ', 12) Service
- from co2servicelist t,
- co2categorylist c,
- co2group g,
- co2brand b,
- co2grouplevel l,
- co2grouptype y
- where t.categorylistid = c.id
- and c.groupid = g.id
- and g.id = b.groupid
- and g.id = l.groupid
- and g.grouptypeid = y.id;
- --create view report_molog
- create or replace view report_molog as
- select Rpad(t.msisdn, 14) || trim(decode(a.id, 1, 0, 3, 2, 4, 1)) ||
- Rpad(nvl(d.servicelistname, ' '), 40) ||
- trim(Rpad(to_char(t.creationdate, 'YYYY-MM-DD HH:MI:SS'), 19)) molog
- from co2transactionlog t, co2transactionlogdetail d, co2actiontype a
- where t.id = d.transactionlogid
- and d.actiontypeid = a.id
- and t.originid = 1
- and a.id in (1, 3, 4);
- create or replace view report_mtlog as
- select Rpad(t.msisdn, 14) || trim(decode(a.id, 1, 0, 3, 2, 4, 1)) || Rpad(nvl(d.servicelistname, ' '), 40) ||
- trim(Rpad(to_char(t.creationdate, 'YYYY-MM-DD HH:MI:SS'), 19)) ||
- decode(t.erroroccured, 'N', '0', 'Y', '1') mtlog
- from co2transactionlog t,
- co2transactionlogdetail d,
- co2actiontype a,
- co2origin b
- where t.id = d.transactionlogid
- and d.actiontypeid = a.id
- and t.directionid = 2
- and b.id = t.originid
- and a.id in (1, 3, 4) ;
- -- create view for user
- create or replace view REPORT_USER as
- select RPAD(t.msisdn, 14) || RPAD(b.id, 2) ||
- RPAD(decode(p.id, 1, 3, 2, 2, 3, 1) || l.userlevelid, 5) ||
- RPAD(t.imsi, 16) || RPAD(c.cardproviderid, 2) ||
- RPAD(c.protocolversionid, 3) || Rpad(c.cardbatchid, 2) ||
- RPAD(nvl(query_user_menu(c.id),' '), 500) userinfo
- from co2user t,
- co2card c,
- co2grouplevel l,
- co2group g,
- co2grouptype p,
- co2brand b
- where t.cardid = c.id
- and c.grouplevelid = l.id
- and l.groupid = g.id
- and g.id = b.groupid
- and g.grouptypeid = p.id;
- --create function for concat AID string
- create or replace function query_user_menu(id in varchar2) return varchar2 is
- Result varchar2(500);
- c_id varchar2(500);
- a_id number;
- cursor region_cur is
- select t.servicelistid, t.profilestate, t.isopen
- from co2currentserviceprofile t
- where t.cardid = id;
- begin
- for my_cur in region_cur loop
- select t.aidserviceid, UPPER(trim(to_char(c.aidcategoryid, '0x')))
- into a_id, c_id
- from co2servicelist t, co2categorylist c
- where my_cur.servicelistid = t.id
- and t.categorylistid = c.id;
- if c_id is not null and a_id is not null then
- if my_cur.profilestate = 'Y' then
- a_id := a_id + 32768;
- end if;
- if my_cur.isopen = 'Y' then
- a_id := a_id + 1024;
- end if;
- a_id := a_id + 16384;
- Result := CONCAT(Result, c_id);
- Result := concat(Result, UPPER(trim(to_char(a_id, '0xxx'))));
- Result := concat(Result, '|');
- end if;
- end loop;
- return(Result);
- end query_user_menu;
- /