“Function created with compilation errors”如何修复此错误?

huangapple go评论55阅读模式
英文:

how to fix this "Function created with compilation errors"

问题

创建或替换函数 invoice_total_price_function
	(p_invoice_num IN invoice_line.invoice_num%TYPE)
	返回 NUMBER
	是
	v_price book.price%TYPE :=0;
	v_order_quantity invoice_line.order_quantity%TYPE :=0;
	开始
		选择 price, order_quantity
		INTO v_price, v_order_quantity
		FROM book, invoice_line
		WHERE book.isbn_code = invoice_num.isbn_code
		AND invoice_num = p_invoice_num;
		返回 SUM(v_price * v_order_quantity);
	结束 invoice_total_price_function;

希望找出所有发票行的总价格,汇总到单个发票中。
我如何知道应该编辑哪一行?谢谢

英文:
Create or replace FUNCTION invoice_total_price_function
	(p_invoice_num IN invoice_line.invoice_num%TYPE)
	RETURN NUMBER
	IS
	v_price book.price%TYPE :=0;
	v_order_quantity invoice_line.order_quantity%TYPE :=0;
	BEGIN
		SELECT price, order_quantity
		INTO v_price, v_order_quantity
		FROM book, invoice_line
		WHERE book.isbn_code = invoice_num.isbn_code
		AND invoice_num = p_invoice_num;
		RETURN SUM(v_price * v_order_quantity);
	END invoice_total_price_function;

hoping to find out the total price of all the invoice line into a single invoice.
how can i see which line i should be edited? Thank you

答案1

得分: 0

  1. 你的 SUM 放错地方了。如果你想要对多行进行聚合,请在查询中进行。
  2. 不要使用隐式连接。使用 ANSI 连接。

你的最终函数应该类似于这样:

Create or replace FUNCTION invoice_total_price_function
    (p_invoice_num IN invoice_line.invoice_num%TYPE)
    RETURN NUMBER
    IS
    v_total_price NUMBER :=0;
    BEGIN
        SELECT SUM(price * order_quantity)
        INTO v_total_price
        FROM book
        JOIN invoice_line on (isbn_code = invoice_line.isbn_code)
        WHERE invoice_line.invoice_num = p_invoice_num;

        RETURN v_total_price;
    END invoice_total_price_function;

请注意,我在这里假设 v_total_price 的类型是 NUMBER(因为这是函数设计的返回类型),但你应该根据你的需要进行检查和适应。

英文:
  1. Your SUM is out of place. If you want aggregation of multiple rows - do it in your query.
  2. Don't use implicit joins. Use ANSI join.

Your final function should look something like this:

Create or replace FUNCTION invoice_total_price_function
    (p_invoice_num IN invoice_line.invoice_num%TYPE)
    RETURN NUMBER
    IS
    v_total_price NUMBER :=0;
    BEGIN
        SELECT SUM(price * order_quantity)
        INTO v_total_price
        FROM book
        JOIN invoice_line on (isbn_code = invoice_num.isbn_code)
        WHERE invoice_num = p_invoice_num;

        RETURN v_total_price;
    END invoice_total_price_function;

Please note, that here I assumed that type of v_total_price would be NUMBER (since that's what functions designed to return), but you should check and suite it to your needs.

huangapple
  • 本文由 发表于 2023年4月16日 23:40:48
  • 转载请务必保留本文链接:https://go.coder-hub.com/76028718.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定