【问题标题】:Oracle Procedure error "declaration of cursor 'C' us incomplete or malformed"?Oracle过程错误“游标'C'的声明我们不完整或格式错误”?
【发布时间】:2015-12-06 02:51:44
【问题描述】:

当我尝试运行程序 printshipment 时,我得到一个错误

PLS-00341: declaration of cursor 'C' is incomplete or malformed

我的游标声明有什么问题以及如何解决?

CREATE OR REPLACE PROCEDURE printshipment(onmbr  IN shipment.onum%TYPE,
                                          shnmbr IN shipment.snum%TYPE)
IS
  CURSOR c IS
    SELECT
      shcontent.inum  ino,
      item.descr      description,
      item.qtyshipped q,
      item.unitprice  u,
      u * q           cost
     FROM shcontent, item
    WHERE shcontent.snum = shnmbr
      AND shcontent.onum = onmbr
      AND shcontent.inum = item.inum;

  rec c%ROWTYPE;

  BEGIN

    OPEN c;

    FETCH c INTO rec;

    IF c%NOTFOUND THEN
      dbms_output.put_line('No Shipment');
    END IF;

    CLOSE c;   
  END;
/

【问题讨论】:

    标签: oracle syntax compiler-errors cursor


    【解决方案1】:

    我认为如果您想在游标的查询中包含可变参数,您必须将其声明为参数化游标,如下所示:

    CURSOR C (c_onmbr IN Shipment.onum%type, c_shnmbr IN Shipment.snum%type)
    IS 
      SELECT ShContent.inum Ino, Item.descr description, Item.Qtyshipped Q,   
          Item.UnitPrice U, U * Q COST
      FROM ShContent, Item
      WHERE ShContent.snum = c_shnmbr
        AND ShContent.onum = c_onmbr
        AND ShContent.inum = Item.inum;
    

    然后

    OPEN C(onmbr, shnmbr);
    

    不过,我可能弄错了;我的 Oracle 证书有点过时了。

    【讨论】:

    • 我觉得你搞错了,变量可以在SELECT语句中引用。
    【解决方案2】:

    不能在同一个 SELECT 列表中引用列别名。除非“q”和“u”也是表中的列,否则这部分语句是无效的:

      item.qtyshipped q,
      item.unitprice  u,
      u * q           cost
    

    要么将 u * q 替换为 item.qtyshipped * item.unitprice,要么将 SELECT 语句包装在另一个内联视图中,然后引用别名。此外,错误消息中可能还有更多信息。出现问题时,请务必发布整个错误消息。

    【讨论】:

      猜你喜欢
      • 2021-03-29
      • 2014-01-09
      • 1970-01-01
      • 1970-01-01
      • 2021-04-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-12-25
      相关资源
      最近更新 更多