0

我正在尝试遍历由第一个 select 语句提取的行(仅包含一列),然后使用我要执行 select 语句的该行的值。但这里的问题是我的第一个 select 语句返回三行,它可能更多取决于具体情况。但是当它到达主选择语句时,它会说“在这个 SELECT 语句中需要一个 INTO 子句

     CREATE OR REPLACE PROCEDURE TAJTEST

   ( CapRefCursor OUT CAP_CUR_PKG.CapCur)

IS

/******************************************************************************
   NAME:       TAJTEST
   PURPOSE:     Testing Multiple lessee selection

   REVISIONS:
   Ver        Date        Author           Description
   ---------  ----------  ---------------  ------------------------------------
   1.0        05/08/2013   Tajamul Iqbal       1. Created this procedure.

   NOTES:

******************************************************************************/





 V_APPLICANTTYPE varchar2(5);

BEGIN      

DECLARE


   Cursor    c1 IS   select  fn_applicanttype(applicant_type.application_number,applicant_type.identification_code) as APPLICANTTYPE   from applicant_type where 
   applicant_type.application_number = 'A000000807000' ;                                                           

BEGIN
    OPEN c1;
        LOOP
      FETCH c1 INTO V_APPLICANTTYPE;
      EXIT WHEN c1%NOTFOUND;                                

                         IF V_APPLICANTTYPE='IC'   then                                      

                           SELECT 'Individual' as App_Type,
                                             substr(APPLICANT_DETAIL.APPLICATION_NUMBER, 1, 10 ) as APPLICATION_NUMBER,
                                             APPLICANT_DETAIL.IDENTIFICATION_CODE,

                                            APPLICANT_DETAIL.APPLICANT_ID AS CUSTOMER_ID ,

                                            APPLICANT_DETAIL.FIRST_NAME AS NAME,
                                            APPLICANT_DETAIL.LESSEE_NO as LESSEE,
                                            APPLICANT_DETAIL.SHORT_NAME as shortname,
                                            APPLICANT_DETAIL.SSN_BUSS_ID as ssnBusinessID,
                                            APPLICANT_DETAIL.PAYMENT_DUE_DAY as paymentDueDay,
                                            APPLICANT_DETAIL.USE_TAX_EXEMPT_CDE as useTaxExemptCode,
                                            Applicant_Detail.remit_address as remittanceAddress,
                                            APPLICANT_TYPE.MAIN_APPLICANT ,
                                            APPLICANT_TYPE.APPLICANT_TYPE,
                                            ADDRESS.CITY,
                                            ADDRESS.STATE_CDE as state,    
                                            ADDRESS.UNIT_NO AS Address1, 
                                            ADDRESS.POST_CODE_2 as zipCode,                            
                                            contract_detail.LP_PORTFOLIO as Portfolio,                            
                                            contract_detail.LP_COMPANY AS company,                            
                                            contract_detail.LP_REGION AS region,                            
                                            contract_detail.LP_OFFICE AS office                              
                                            FROM  APPLICANT_DETAIL   INNER JOIN                              
                                            ADDRESS  on APPLICANT_DETAIL.APPLICATION_NUMBER= ADDRESS.APPLICATION_NUMBER                              
                                            and ADDRESS.ADDRESS_CODE=1 and address.identification_code=1                              
                                            INNER JOIN  CONTRACT_DETAIL  on APPLICANT_DETAIL.APPLICATION_NUMBER= CONTRACT_DETAIL.APPLICATION_NUMBER                                                           
                                            Inner Join Applicant_type on APPLICANT_TYPE.APPLICATION_NUMBER= APPLICANT_DETAIL.APPLICATION_NUMBER and   
                                            APPLICANT_TYPE.IDENTIFICATION_CODE= APPLICANT_DETAIL.IDENTIFICATION_CODE                                
                                            WHERE (APPLICANT_DETAIL.APPLICATION_NUMBER ='A000000807000');





                                   else if  V_APPLICANTTYPE='CL'   then

                                         SELECT  'Company' as App_Type,
                                                   substr(Company_DETAIL.APPLICATION_NUMBER, 1, 10 ) as APPLICATION_NUMBER,
                                                    Company_DETAIL.IDENTIFICATION_CODE,

                                                    Company_DETAIL.Lessee_No AS CUSTOMER_ID ,
                                                     APPLICANT_TYPE.MAIN_APPLICANT ,
                                                    APPLICANT_TYPE.APPLICANT_TYPE,
                                                    Company_DETAIL.Name AS NAME,
                                                    Company_DETAIL.LESSEE_NO as LESSEE,
                                                    Company_DETAIL.SHORT_NAME as shortname,
                                                    Company_DETAIL.SSN_BUSS_ID as ssnBusinessID,
                                                    Company_DETAIL.PAYMENT_DUE_DAY as paymentDueDay,
                                                    Company_DETAIL.USE_TAX_EXEMPT_CDE as useTaxExemptCode,
                                                    Company_DETAIL.remit_address as remittanceAddress,

                                                    ADDRESS.CITY,
                                                    ADDRESS.STATE_CDE as state,
                                                    ADDRESS.UNIT_NO AS Address1,
                                                    ADDRESS.POST_CODE_2 as zipCode,
                                                     contract_detail.LP_PORTFOLIO as Portfolio,
                                                     contract_detail.LP_COMPANY AS company,
                                                    contract_detail.LP_REGION AS region,
                                                    contract_detail.LP_OFFICE AS office

                                                  FROM Company_DETAIL         INNER JOIN  ADDRESS  on
                                                  Company_DETAIL.APPLICATION_NUMBER= ADDRESS.APPLICATION_NUMBER

                                                  and ADDRESS.ADDRESS_CODE=1 and address.identification_code=1
                                                  INNER JOIN  CONTRACT_DETAIL  on Company_DETAIL.APPLICATION_NUMBER= CONTRACT_DETAIL.APPLICATION_NUMBER
                                                  Inner Join Applicant_type on APPLICANT_TYPE.APPLICATION_NUMBER= COMPANY_DETAIL.APPLICATION_NUMBER and 
                                                  APPLICANT_TYPE.IDENTIFICATION_CODE= COMPANY_DETAIL.IDENTIFICATION_CODE
                                                  WHERE (Company_DETAIL.APPLICATION_NUMBER = 'A000000807000');
                       end if;

                       end if;

   END LOOP;
    CLOSE c1;      

    END;
 END TAJTEST;
/

请在这方面帮助我。太感谢了。

4

1 回答 1

0

在一个过程或函数中,你不能只是SELECT; 您必须使用以下方法之一SELECT 进入某事:

  • SELECT table.col1, table.col2 INTO var1, var2 FROM ...,
  • OPEN <cursor> FOR SELECT table.col1, ...

在这种情况下,您需要OPEN <cursor> FOR SELECT...,并且OUT参数是您要选择的光标。例如,第一个SELECT应该开始为:

IF V_APPLICANTTYPE='IC'   then
  OPEN CapRefCursor FOR
    SELECT 'Company' as App_Type, ...

第二个SELECT(在 之后else if)需要做同样的事情。

于 2013-05-07T16:25:57.163 回答