我一直收到错误:编译错误成功。我的代码怎么办?我在sqlfiddle中尝试过,但是我收到了一个无效的SQL语句错误。据我所知,这是PL / SQL的正确语法
create or replace PROCEDURE PRC_CALC
(W_ORDERID_IN IN NUMBER)
AS
W_PARTSERVICEID VARCHAR2(10);
W_EXIST_FLAG NUMBER(1) :=0;
W_SUBTOTAL NUMBER(9) :=0;
W_TAX NUMBER(9) :=0.07;
W_DISCOUNT NUMBER(9) :=0;
W_TOTAL NUMBER(9) :=0;
BEGIN
SELECT COUNT(*)
INTO W_EXIST_FLAG
FROM tblJobOrders
WHERE fldOrderId = W_ORDERID_IN;
IF W_EXIST_FLAG = 1 THEN
CURSOR CUR_ORDERCHARGES IS
SELECT fldPartServiceId
FROM tblOrderCharges
WHERE fldOrderId = W_ORDERID_IN;
OPEN CUR_ORDERCHARGES;
LOOP
FETCH CUR_ORDERCHARGES
INTO W_PARTSERVICEID
EXIT WHEN CUR_ORDERCHARGES%NOTFOUND;
SELECT fldPartServiceAmount, fldDiscountPercent
INTO W_SUBTOTAL, W_DISCOUNT
FROM tblPartsServices
WHERE fldPartServiceId = W_PARTSERVICEID;
W_DISCOUNT := (W_SUBTOTAL*(W_DISCOUNT*.01));
W_TAX := (W_TOTAL*W_TAX);
W_TOTAL := W_SUBTOTAL - W_DISCOUNT;
W_TOTAL := W_TOTAL + W_TAX;
htp.prn('Your subtotal is: $' ||W_SUBTOTAL||'<br>');
htp.prn('Your Discount is: $' ||W_DISCOUNT||'<br>');
htp.prn('Your Tax is: $' ||W_TAX||'<br>');
htp.prn('Your Total is: $' ||W_TOTAL||'<br>');
END LOOP;
CLOSE CUR_ORDERCHARGES;
ELSE
htp.prn('The Order Id: '||W_ORDERID_IN||' does not exist in the database');
END IF;
END;
答案 0 :(得分:1)
您的变量声明需要工作
W_PARTSERVICEID VARCHAR2;应该具有诸如W_PARTSERVICEID VARCHAR2(250);
之类的大小您的号码声明可以使用,但最好还指定一个大小
W_EXIST_FLAG NUMBER;应该是W_EXIST_FLAG NUMBER(9);
未声明W_EXIST_ORDER_FLAG,也应如此。
作为超出您的问题的编程实践,您应该检查进入过程和游标的值是否为空或零。
CURSOR CUR_ORDERCHARGES应该使用其他声明声明或放在新的DECLARE BEGIN END块中
你在you FETCH the cursor时缺少一个半冒号,它应该是
FETCH CUR_ORDERCHARGES
INTO W_PARTSERVICEID;
EXIT WHEN CUR_ORDERCHARGES%NOTFOUND;
答案 1 :(得分:0)
第一个查询中使用的W_EXIST_ORDER_FLAG未定义。也许,你的意思是W_EXIST_FLAG?