【问题标题】:PL/SQL Select After Select Into in Oracle 11gOracle 11g 中选择后的 PL/SQL 选择
【发布时间】:2016-05-21 01:48:52
【问题描述】:

在 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 编译错误。 *行动:

我做错了什么?

【问题讨论】:

  • 第二个 SELECT 语句没有INTO 子句。第二个 SELECT 会返回一行还是多行?
  • 您是否希望最后一次选择返回记录集?如果是这样,您是否设置了正确的RefCursor 来执行此操作? @BobJarvis 你的意思是第三对吗?
  • 最后一个 select 语句应该返回多行。我已经编辑了原始问题,以提供一些关于我正在尝试做的背景。

标签: sql plsql oracle11g


【解决方案1】:

更改您的代码,以便将最后一个 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;

祝你好运。

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2017-05-29
    • 2020-05-29
    • 2012-02-26
    • 1970-01-01
    • 2014-08-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多