PL / SQL在Oracle 11g中选择后选择

时间:2016-02-10 15:52:28

标签: sql plsql oracle11g

我在PL / SQL中运行下面的查询时遇到错误。我想在最后的select语句中返回多行。开始的select into语句是将各种引用数据ID传递给最终select的where子句。

declare
   v_statusIdActive NUMBER;
   v_requestTypeId NUMBER;
   v_licenseTypeId NUMBER; 
   v_licenseCategoryId NUMBER;

begin

   select RefStatusId 
   into v_statusIdActive
   from RefStatus
   where 
    StatusNameEn = 'Active'
    and rownum = 1;

   SELECT REQUESTTYPEID, LICENSETYPEID, LICENSECATEGORYID 
   INTO v_requestTypeId, v_licenseTypeId, v_licenseCategoryId
   FROM REQUEST
   WHERE
    REQUESTID = 78
    and rownum = 1;


  select * from FeeRequestMapping frm
    inner join Fee f on frm.FeeId = f.FeeId
  where
    frm.RequestTypeId = v_requestTypeId
    and frm.LicenseTypeId = v_licenseTypeId
    and frm.LicenseCategoryId = v_licenseCategoryId
    and frm.RefStatusId = v_statusIdActive;

  end;

错误是:

  

错误报告 - ORA-06550:第24行第7行:PLS-00428:INTO子句   预期在此SELECT语句中   06550. 00000 - “行%s,列%s:\ n%s”   *原因:通常是PL / SQL编译错误。   *操作:

我做错了什么?

1 个答案:

答案 0 :(得分:2)

更改代码,以便将最后一个SELECT用作游标,如:

declare
   v_statusIdActive NUMBER;
   v_requestTypeId NUMBER;
   v_licenseTypeId NUMBER; 
   v_licenseCategoryId NUMBER;

begin
  select RefStatusId 
    into v_statusIdActive
    from RefStatus
    where StatusNameEn = 'Active' and
          rownum = 1;

  SELECT REQUESTTYPEID, LICENSETYPEID, LICENSECATEGORYID 
    INTO v_requestTypeId, v_licenseTypeId, v_licenseCategoryId
    FROM REQUEST
    WHERE REQUESTID = 78 and
          rownum = 1;

  FOR aRow IN (select *
                 from FeeRequestMapping frm
                 inner join Fee f
                   on frm.FeeId = f.FeeId
                 where frm.RequestTypeId = v_requestTypeId and 
                       frm.LicenseTypeId = v_licenseTypeId and 
                       frm.LicenseCategoryId = v_licenseCategoryId and 
                       frm.RefStatusId = v_statusIdActive)
  LOOP
    NULL;  -- add processing for each 'aRow' returned by the cursor here
  END LOOP;
END;

祝你好运。