0

我创建的 customer_ty 对象有一个嵌套表,包括

CREATE TYPE deposit_ty as object(
depNo number,
depCategory ref depcategory_ty,
amount number,
period number
)
/

CREATE TYPE deposit_tbl as table of deposit_ty
/

CREATE TYPE customer_ty as object(
custId varchar2(4),
custName varchar2(10),
address address_ty,
dob date,
deposits deposit_tbl
)
/

我编写了一个代码来计算每个客户存入的总金额。这是我编写的代码;

alter type customer_ty
add member function totDeposits return number cascade
/

create or replace type body customer_ty as
member function totDeposits 
return number is
total number;
BEGIN
    select sum(d.amount) into total
    from table(self.deposits) d;
    group by self.custId,self.custName
    return total;
END totDeposits;
END;
/

但是我收到一条警告说“使用编译错误创建的类型主体”。我能做些什么来摆脱这个?

4

1 回答 1

1

如果您show errors在收到“创建时出现编译错误”消息后立即执行此操作,您将看到如下内容:

LINE/COL ERROR
-------- ------------------------------------------------------------------------------
8/5      PLS-00103: Encountered the symbol "GROUP" when expecting one of the following:

您还可以查询user_errorsall_errors查看针对任何 PL/SQL 对象的未解决错误。

在这种情况下,这是一个简单的错字;您的分号放错了位置;代替:

select sum(d.amount) into total
from table(self.deposits) d;
group by self.custId,self.custName

它应该是:

select sum(d.amount) into total
from table(self.deposits) d
group by self.custId,self.custName;

在您的版本中,... d;正在终止该 SQL 语句 - 这现在将是无效的,因为该截断语句没有 group by 子句;但它并没有抱怨这一点,因为它将group by ...视为一个单独的语句,并且这不是任何 PL/SQL 识别为查询、语句、控制循环等的开始,所以它放弃了。

于 2016-03-22T17:37:03.487 回答