嗨,伙计,我有一个查询给我以下错误:
ORA-01791: not a SELECTed expression   
这是选择表达式,请你告诉我为什么?
declare
 freqLettura varchar2(64);
 billingcy  varchar2(64);
begin
freqLettura := null;
billingcy := null;
for rec in ( select distinct(fn_get_facilityid(z.uidfacility) ) as a, 1 as b 
            from facilityhistory z, 
            locality l , 
            plant p , 
            ztmp_sam_tb_sdv zsdv , 
            ztmp_sam_tb_plantcode zplant , 
            sam_tb_ca_pdr sam,  
            meterhistory mh, 
            meter m , 
            meterclass mc 
            where 
                Z.UIDLOCALITY = L.UIDLOCALITY and  
                p.UIDPLANT = L.UIDPLANT  and 
                z.uidaccount = zsdv.uidaccount and 
                p.plantcode = zplant.plantcode and   
                sam.uidfacility = z.uidfacility and
                z.stoptime is null and
                sam.status = 'U' and
                mh.uidfacility = z.uidfacility and 
                mh.uidmeter = m.uidmeter and 
                m.uidmeterclass = mc.uidmeterclass and 
                (billingcy is null or p.UIDBILLINGCYCLE = billingcy )
            AND
            (
                (
                (freqLettura = 'G') AND   ( mh.corrmeterid is not null and mh.stoptime is null and mc.maxflowmeter >= SAM_FN_GET_PARAMETER_FLOAT('MAXFLOWMET_DETT_GIORN'))
                )
                OR
                (
                nvl(freqLettura,'nullo') <> 'G' AND (freqLettura is null or sam.readfrequency = freqLettura)
                )
            ) and ROWNUM = 1 order by sam.stoptime, sam.uidsamtbpdr desc ) loop
begin
    insert into ztmp_sam_tb_elab_pdr (facilityid, uidbatchrequest) VALUES  (rec.a, rec.b);
exception
     when dup_val_on_index then
        null;
  end;
end loop;    
结尾;