当我尝试运行程序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;
/
答案 0 :(得分:0)
我认为如果你想在游标查询中包含变量参数,你必须将它声明为参数化游标,如下所示:
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证书 有点过时了。
答案 1 :(得分:0)
列别名不能在同一SELECT列表中引用。除非“q”和“u”也是表中的列,否则该部分语句无效:
item.qtyshipped q,
item.unitprice u,
u * q cost
将u * q
替换为item.qtyshipped * item.unitprice
或将SELECT语句包装在另一个内联视图中,然后引用别名。此外,错误消息中可能还有一些信息。当出现问题时,请务必发布整个错误消息。