title: Error(4,1): PLS-00103: Encountered the symbol "AS"
body: <p>What is wrong with the following function I am trying to create and compile?</p>
  
  <p>I get this error code and I'm unsure exactly what is wrong with it.</p>
  
  <pre><code>Error(4,1): PLS-00103: Encountered the symbol "AS" when expecting one of the following:     return 
  </code></pre>
  
  <p>Code:</p>
  
  <pre><code>create or replace FUNCTION BOD_FM_FSCS_A_Data(
      -- Add the parameters for the function here
      p_ExclusionsOnly NUMBER DEFAULT 0 )
  AS
  IS
  BEGIN
    INSERT INTO @ATable
    SELECT DISTINCT SCVID,
      Title,
      Forename1,
      Forename2,
      Forename3,
      CASE
        WHEN CompanyName IS NULL
        OR CompanyName    =''
        THEN Surname
        ELSE CompanyName
      END AS Surname ,
      PreviousName,
      NI_No,
      PassportNo,
      OtherNational_ID,
      OtherNational_ID_No ,
      CompanyNo,
      DateOfBirth
    FROM DIM_FM_FSCS_Customer customer
    INNER JOIN DIM_FM_FSCS_CustomerAccLink cal
    ON cal.FSCSCustomerLink=customer.ID
    INNER JOIN DIM_FM_FSCS_Account acc
    ON acc.ID              =cal.FSCSAccountLink
    AND ( (p_ExclusionsOnly=1
    AND acc.ExclusionCode &lt;&gt;'')
    OR (p_ExclusionsOnly   =0
    AND acc.ExclusionCode  = ''));
    RETURN
  END;
  </code></pre>