select doti."name",
rkk.id,
rkk.id_type,
rkk.regnumprist,rkk.regnumcnt,
rkk.regnumfin,
convertid.sochiunid,
convertid.notesunid from f_dp_rkk rkk
join (select fdr.id as id,
fdr.id_type as id_type,
to_char(cast((fdr.id_type * 10^12) as bigint) + fdr.id, 'FM0000000000000000') as sochiunid
from f_dp_rkkbase fdr) rkkbase on rkk.id = rkkbase.id and rkk.id_type = rkkbase.id_type
join (select SUBSTRING(npm.punid FOR 16) as sochiunid,
npm.nunid as notesunid
from nunid2punid_map npm) convertid on rkkbase.sochiunid=convertid.sochiunid
join domain_object_type_id doti on doti.id = rkk.id_type |