简体   繁体   中英

Invalid Identifier in Oracle Function

This is my SQL ;

select a.hesap_no, 
       a.teklif_no1 || '/' || a.teklif_no2 as teklif, 
       a.mus_k_isim as musteri, 
       b.marka, 
       c.sasi_no, 
       c.sasi_durum, 
       d.tas_mar, 
       nvl(risk_sasi(a.teklif_no1, a.teklif_no2, c.urun_sira_no, c.sira_no), 0) as risk,
       nvl(mv_sasi(a.teklif_no1, a.teklif_no2, c.sira_no, c.urun_sira_no, sysdate), 0) as mv
  from s_teklif a,  
       s_urun b, 
       s_urun_detay c, 
       koc_ktmar_pr d
 where a.teklif_no1 || a.teklif_no2 = b.teklif_no1 || b.teklif_no2

This is my MV_SASI Function;

create or replace
FUNCTION MV_SASI 
(
  TEK1 IN VARCHAR2,
 TEK2 IN NUMBER,
 SIRA IN NUMBER,
 USIRA IN NUMBER,
 DT IN DATE
) 
RETURN NUMBER IS MV number;

fat number;
adet number;
pd number;
pds number;
kt date;
ktv number;
dtv number;
frk number;
yfrk number;

TKM VARCHAR2(10);

BEGIN       

SELECT COUNT(*)
  INTO adet
  FROM S_URUN_DETAY
  WHERE (SASI_DURUM IS NULL OR SASI_DURUM IN ('A','R'))
  AND TEKLIF_NO1 = TEK1
  AND TEKLIF_NO2 = TEK2;

SELECT SUM(CASE WHEN B.SASI_DURUM IS NULL OR B.SASI_DURUM IN ('A','R') THEN A.KDV_FIYAT ELSE 0 END)
  INTO fat
  FROM S_URUN A,S_URUN_DETAY B
    WHERE  A.TEKLIF_NO1 = tek1
    AND A.TEKLIF_NO2 = tek2
    AND A.TEKLIF_NO1 = B.TEKLIF_NO1
      AND A.TEKLIF_NO2 = B.TEKLIF_NO2
       AND A.SIRA_NO = B.URUN_SIRA_NO;

SELECT KULLAN_TARIH
INTO kt
FROM S_TEKLIF
 WHERE TEKLIF_NO1 = tek1
       AND TEKLIF_NO2 = tek2 ; 

yfrk:= EXTRACT(YEAR FROM dt) - EXTRACT(YEAR FROM kt);

  ktv := EXTRACT(MONTH FROM kt);
  dtv := EXTRACT(MONTH FROM dt);

  frk := yfrk * 12 + (dtv-ktv);

IF frk  <= 0 THEN
  pd := fat * 0.85;
ELSE
  pd := fat*0.85 - (fat * 0.0101 * frk);
END IF;

SELECT NVL(ROUND((CASE WHEN SASI_DURUM IS NULL OR SASI_DURUM IN ('A','R') THEN pd / adet ELSE 0 END),2),0)
INTO pds
FROM S_URUN_DETAY
WHERE TEKLIF_NO1 = TEK1
AND TEKLIF_NO2 = TEK2
AND URUN_SIRA_NO = USIRA
AND SIRA_NO = SIRA;

RETURN pds;

END;

But in my page i getting an error with this line of code;

 OracleDataReader dr = myCommand.ExecuteReader(System.Data.CommandBehavior.CloseConnection);

在此处输入图片说明

Where am i doing wrong?

Best Regards, Soner

myCommand is;

select a.hesap_no, 
       a.teklif_no1 || '/' || a.teklif_no2 as teklif, 
       a.mus_k_isim as musteri, 
       b.marka, 
       c.sasi_no, 
       c.sasi_durum, 
       d.tas_mar, 
       nvl(risk_sasi(a.teklif_no1, a.teklif_no2, c.urun_sira_no, c.sira_no), 0) as risk,
       nvl(mv_sasi(a.teklif_no1, a.teklif_no2, c.sira_no, c.urun_sira_no, sysdate), 0) as mv
  from s_teklif a,  
       s_urun b, 
       s_urun_detay c, 
       koc_ktmar_pr d
 where a.teklif_no1 || a.teklif_no2 = b.teklif_no1 || b.teklif_no2
   and a.teklif_no1 || a.teklif_no2 = c.teklif_no1 || c.teklif_no2
   and b.sira_no = c.urun_sira_no
   and b.distributor = d.dist_kod
   and b.marka = d.marka_kod
   and b.urun_kod = d.tas_kod  
   and a.hesap_no in (select a.hesap_no 
                        from s_teklif a 
                       where a.mus_k_isim in (system.collections.arraylist)
                     )

I have come accross that kind of problem a short time ago. The problem was:

Stupid oracle has not a stacktrace type error handling mechanism so it only gives the top error, which prevents us to see the other ones.

Your function MV_SASI has no grant to be used by the oracle user. So Oracle could not find it and tried to run it like MV_SASI is a column name. so it gives the error.

Check the grant and visibility settings of the MV_SASI func.

This bit at the end of your SQL seems odd: WHERE A.MUS_K_ISIM IN (System.Collections.ArrayList) . If that's really your actual SQL text, then I think this is your problem. Oracle has no idea what System.Collections.ArrayList is.

Moreover, if what you're trying to do is bind an actual arraylist into the SQL so that you can test against it with IN -- that won't work. Even if you successfully got it to bind to a known datatype in Oracle, the syntax of IN is such that the operand is compared to each element in a comma-delimited list of identifiers -- Oracle won't break the list apart for you.

You either need to bind each item of the list so you have a condition like A.MUS_K_ISIM IN (:bind1, :bind2, :bind3) , or map your arraylist to a nested table or varray type in Oracle so you can use a subquery with IN, like A.MUS_K_ISIM IN (SELECT columnValue FROM TABLE(CAST(:bindlist AS someOracleType))) .

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM