3

我正在为我的家庭作业做这个。当我运行它时,我收到错误:

PACKAGE PKG_Q4 Compiled.
 Warning: execution completed with warning
 PACKAGE BODY PKG_Q4 Compiled.
 50/12          PLS-00330: invalid use of type name or subtype name.

我已经调查过了,但我似乎无法找到解决它的方法。它指向这条线:

INTO v_Room_Number, v_Pet_Status, v_Customer_Source_Description, v_Invoice_Total

这是我的代码:

    CREATE OR REPLACE PACKAGE BODY PKG_Q4 
    AS
      FUNCTION FN_Q4
        (p_First_Name VARCHAR2, p_Last_Name VARCHAR2)
      RETURN VARCHAR2 
        AS
        v_Output VARCHAR2(500);
        v_Room_Number NUMBER(3,0);
        v_Pet_Status CHAR(1);
        v_Customer_Source_Description VARCHAR2(30);
        v_Invoice_Total NUMBER(7,2);
        v_First_Name VARCHAR2(15);
        v_Last_Name VARCHAR2(20);
        v_Customer_Code CHAR(4);
        v_Registration_Status_Code CHAR(1);


        BEGIN

          SELECT First_Name, Last_Name
          INTO v_First_Name, v_Last_Name
          FROM Customer
          WHERE First_Name = p_First_Name AND
                Last_Name = p_Last_Name;




          Select Registration_Status_Code
          INTO v_Registration_Status_Code
          FROM Registration_Status;






          IF v_Registration_Status_Code = 'N' THEN
            SELECT Room.Room_Number, Room.Pet_Status, Customer_Source.Customer_Source_Description, Invoice.Invoice_Total
            INTO v_Room_Number, v_Pet_Status, v_Customer_Source_Description, v_Invoice_Total
            FROM Registration , Customer , Customer_Source , Room , Invoice 
            WHERE Customer.customer_code = Registration.customer_code AND
                  Customer_Source.customer_source_code = Customer.customer_source_code AND
                  Room.room_number = Registration.room_number AND
                  Registration.registration_number = Invoice.registration_number;
                v_Output := 'Room Number:' || v_Room_Number ||'Pet Status:' || v_Pet_Status ||
                            'Customer Source Code:' || v_Customer_Source_Description ||'Total Cost:' || v_Invoice_Total;

         END IF;
Return Varchar2;
4

1 回答 1

4

我敢打赌问题实际上是这一行,在代码摘录的最底部:

Return Varchar2;

“Varchar2”是一种类型,不能将其用作 RETURN 语句的参数。在函数声明中,RETURN VARCHAR2是正确用法,表示函数返回值的类型。实际的 RETURN 语句应返回该类型的值,例如

RETURN 'This is a string literal';

在你的情况下,我猜你想要:

RETURN v_Output;
于 2012-10-11T00:32:19.183 回答