简体   繁体   中英

SQL ORA 935: Missing Expression

I have gone over the SQL for an hour and can't find why the error is being raised. I have checked all the basic reasons this error can occur and found nothing. I'm suspicious of the CASE statement but it appears to be correct. Can anyone spot the problem or point me in a direction? Thanks

INSERT INTO RPT_HOUSEHLDBATCH
         (CUSTOMERKEY,HOUSEHOLDNBR,CUSTOMERTYPE,LASTNAME,FIRSTNAME,ADDRNBR,AddressLine1,AddressLine2,AddressLine3,
         CITYNAME, STATECD, ZIPCD, SCORE, DATECREATED, RUNDATE, TYPECD, PREVIOUSHHLDNBR)
         SELECT CustomerKey,' || in_HHNbr || ', 
         CASE SUBSTR(CUSTOMERKEY,1,1)
    WHEN ''P'' THEN ''I''
    WHEN ''O'' THEN ''B''
   END CASE,
   a.LastName, 
   a.FirstName, 
   AddrNbr, 
   AddressLine1, 
   AddressLine2, 
   AddressLine3,
   Cityname, 
   StateCd,
   ZipCd, 
   2, b.AddDate, SYSDATE, ''' || in_NewUpd || ''', HouseHoldNbr
   FROM rpt_HouseHldBatchwrk a
JOIN PERS b
ON SUBSTR(a.CUSTOMERKEY,2) = b.PersNbr 
   WHERE CUSTOMERKEY = ''P' || in_PersNbr || '''
UNION 
SELECT CustomerKey,' || in_HHNbr || ', 
         CASE SUBSTR(CUSTOMERKEY,1,1)
    WHEN ''P'' THEN ''I''
    WHEN ''O'' THEN ''B''
   END CASE,
   a.LastName, 
   a.FirstName, 
   AddrNbr, 
   AddressLine1, 
   AddressLine2, 
   AddressLine3,
   Cityname, 
   StateCd,
   ZipCd, 
   2, b.AddDate, SYSDATE, ''' || in_NewUpd || ''', HouseHoldNbr
   FROM rpt_HouseHldBatchwrk a
JOIN ORG b
ON SUBSTR(a.CUSTOMERKEY,2) = b.OrgNbr 
   WHERE CUSTOMERKEY = ''O' || in_OrgNbr || '''

A good strategy to debug such a statement is to pare it down, as @OldProgrammer suggested.

In your case, I'd try to ignore the INSERT and get the SELECT running first.

As it's a UNION of two SELECT s, I'd split them into separate statements, too.

The in_NewUpd and in_PersNbr look strange, just like parameters in a procedure. I'd replace them with fixed known values, like WHERE CUSTOMERKEY LIKE ''P1234''

And please, please don't store SQL in a variable and execute it based on a condition. The syntax for that is to use placeholder like ? in the SQL instead of string concatenation || . You'll flood the cursor cache if you do it wrong.

Turns out the in_HHNbr in some cases was coming in as a null. Concatenating null throws missing expression.

As far as how the code is structured I inherited this code and can't make major changes. I was sent to bug fix.

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