I have this view:

CREATE OR REPLACE VIEW ANAGR ( SITE_ID,
COD_ID, NOP, ADDRESS, PROP) AS
SELECT SITE.SITE_ID, COD_IMM.COD_ID,
'AA',
SITE.ADDRESS1, LS.PROPRIETA
FROM LS, COD_IMM, SITE, RM, DP
WHERE RM.LS_ID = COD_IMM.LS_ID
AND SITE.SITE_ID = COD_IMM.SITE_ID
AND LS.LS_ID = RM.LS_ID
AND SITE.SITE_ID = RM.SITE_ID
AND RM.DV_ID = DP.DV_ID
AND RM.DP_ID = DP.DP_ID
AND (DP.FLAG_GR='2' OR
(DP.FLAG_GR='1' AND COD_IMM.ADMIN IN ('AAAA','TTTT')))
GROUP BY SITE.SITE_ID, COD_IMM.COD_ID,
'AA',
SITE.ADDRESS1,
LS.PROPRIETA

TABLE cod_imm is create every night with a stored procedure:
(INSERT INTO COD_IMM (COD_ID,LS_ID,BL_ID,SITE_ID,ADMIN)
SELECT BL.COD_CONV_BL||'-'||RM.LS_ID COD_ID ,RM.LS_ID,RM.BL_ID,RM.SITE_ID, BL.AMMINISTRATORE
FROM RM,BL
WHERE RM.BL_ID=BL.BL_ID
AND BL.COD_CONV_BL IS NOT NULL
AND RM.SITE_ID IS NOT NULL
AND RM.LS_ID IS NOT NULL
GROUP BY BL.COD_CONV_BL,RM.LS_ID,RM.BL_ID,RM.SITE_ID, BL.AMMINISTRATORE;
COMMIT;
COD_ID...........LS_ID........BL_ID.......SITE_ID. ......ADMIN
A00-0-000001.....000001........000022......000002....... .AAAA
A00-1-000001.....000001........000023......000002....... .AAAA
A00-2-000001.....000001........000024......000002....... .AAAA
A00-3-000001.....000001........000025......000002....... .AAAA
B00-0-123456.....123456........123111......000009....... .AAAA
B00-1-123456.....123456........123112......000009....... .AAAA
S00-0-567890.....567890........222222......567890....... .AAAA
T01-0-567888.....567888........222233......567890....... .AAAA
T01-1-567888.....567888........222234......567890....... .AAAA
R01-0-111111.....111111........000003......999999....... .AAAA
R01-1-111111.....111111........000004......999999....... .AAAA
R01-2-111111.....111111........000008......999999....... .AAAA
Z01-0-333333.....333333........333333......333333....... .AAAA

the cod xxx-y is a autoincrement for each bl_id

TABLE SITE:
SITE_ID PRIMARY KEY

TABLE LS
LS_ID PRIMARY KEY

TABLE DP:
DV_ID PRIMARY KEY
DV_ID
COR
DOM
TEM
FEN
ALA
ALB
ACE

TABLE RM (25000 RECORDS):
RM_ID PRIMARY KEY
BL_ID FK ON BL
SITE_ID FK ON SITE
LS_ID FK ON LS
DV_ID FK ON DP

RM_ID......BL_ID.......SITE_ID.........LS_ID...... .DV_ID
0001.......000022.......000002.........000001..... ..COR
0002.......000023.......000002.........000001..... ..DOM
0003.......000024.......000002.........000001..... ..INT
0004.......000025.......000002.........000001..... ..TEM

0009.......123111.......000009.........123456..... ..COR
0010.......123112.......000009.........123456..... ..FEN
0020.......123113.......000009.........123456..... ..DOM

0031.......222222.......567890.........567890..... ..TEM

0035.......222233.......567888.........567888..... ..TEM
0036.......222234.......567888.........567888..... ..FEN

0037.......000003.......999999.........111111..... ..ALB
0038.......000004.......999999.........111111..... ..ACE
0042.......000008.......999999.........111111..... ..ALA

0055.......333333.......333333.........333333..... ..FEN

in my view I have these values:

COD_ID...........SITE_ID...NOP.....ADDRESS.....PRO P
A00-0-000001.....000002....AA......SSSSSS.......XX
A00-1-000001.....000002....AA......NNNNNN.......XX
A00-2-000001.....000002....AA......CCCCCC.......YY
A00-3-000001.....000002....AA......CVVVVV.......DD
B00-0-123456.....000009....AA......RRRRRR.......XX
B00-1-123456.....000009....AA......RRRRRR.......XX
S00-0-567890.....567890....AA......RRRRRR.......XX
T01-0-567888.....567890....AA......RRRRRR.......VV
T01-1-567888.....567890....AA......RRRRRR.......BB
R01-0-111111.....999999....AA......RRRRRR.......XX
R01-1-111111.....999999....AA......FFFFFF.......XX
R01-2-111111.....999999....AA......RRRRRR.......XX
Z01-0-333333.....333333....AA......RRRRRR.......XX

BUT I'D LIKE TO GET THESE VALUES:
COD_ID...........SITE_ID...NOP.....ADDRESS.....PRO P
A00-0-000001.....000002....EMS......SSSSSS.......XX
A00-1-000001.....000002....EMS......NNNNNN.......XX
A00-2-000001.....000002....EMS......CCCCCC.......YY
A00-3-000001.....000002....EMS......CVVVVV.......DD

B00-0-123456.....000009....EMS......RRRRRR.......XX
B00-1-123456.....000009....EMS......RRRRRR.......XX

S00-0-567890.....567890....TIM......RRRRRR.......XX

T01-0-567888.....567890....FIN......RRRRRR.......VV
T01-1-567888.....567890....FIN......RRRRRR.......BB

R01-0-111111.....999999....EMS......RRRRRR.......XX
R01-1-111111.....999999....EMS......FFFFFF.......XX
R01-2-111111.....999999....EMS......RRRRRR.......XX

Z01-0-333333.....333333....FIN......RRRRRR.......XX

I'd like to get these values in col NOP:

- IF cod_id has DV_ID <> 'FEN' AND DV_ID <> 'TEM' THEN NOP='EMS' (111111)
- IF cod_id has just DV_ID=FEN THEN NOP='FIN' (333333)
- IF cod_id has just DV_ID='TEM' then NOP='TIM' (567890)
- if cod_id has DV_ID='TEM' or DV_ID='FEN' or DV_ID in ('FEN','TEM') but in this cod_id
exists at least an other DV_ID <> from 'FEN' and 'TEM' then NOP='EMS' (000001), (123456)
- if cod_id has just DV_ID='TEM' and DV_ID='FEN' then NOP='FIN' (567888)

I tried with this code but it doesn't run correctly:
CREATE OR REPLACE VIEW ANAGR ( SITE_ID,
COD_ID, NOP, ADDRESS, PROP) AS
SELECT SITE.SITE_ID, COD_IMM.COD_ID,
case when DP.dv_id <> 'FEN' and DP.dv_id <> 'TEM' then 'EMS'
WHEN DP.dv_id = 'TEM' AND COUNT(DISTINCT DP.dv_id)=1 then 'TIM'
WHEN DP.dv_id = 'FEN' AND COUNT(DISTINCT DP.dv_id)=1 then 'FIN'
WHEN DP.dv_id = 'FEN' and DP.dv_id = 'TEM' THEN 'FIN'
WHEN DP.dv_id = 'FEN' OR DP.dv_id = 'TEM' AND COUNT(DISTINCT DP.dv_id)> 1 THEN 'EMS'
ELSE 'EMS' END,
SITE.ADDRESS1, LS.PROPRIETA
FROM LS, COD_IMM, SITE, RM, DP
WHERE RM.LS_ID = COD_IMM.LS_ID
AND SITE.SITE_ID = COD_IMM.SITE_ID
AND LS.LS_ID = RM.LS_ID
AND SITE.SITE_ID = RM.SITE_ID
AND RM.DV_ID = DP.DV_ID
AND RM.DP_ID = DP.DP_ID
AND (DP.FLAG_GR='2' OR
(DP.FLAG_GR='1' AND COD_IMM.ADMIN IN ('AAAA','TTTT')))
GROUP BY SITE.SITE_ID, COD_IMM.COD_ID,
dp.dv_id,
SITE.ADDRESS1,
LS.PROPRIETA


Create this view is very difficult for me....
Could you help me?
Thank you very much!!!