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;
/
但是我收到一条警告说“使用编译错误创建的类型正文”。我能做些什么来摆脱这个?
答案 0 :(得分:1)
如果在收到“使用编译错误创建”消息后立即执行show errors
,您会看到如下内容:
LINE/COL ERROR
-------- ------------------------------------------------------------------------------
8/5 PLS-00103: Encountered the symbol "GROUP" when expecting one of the following:
您还可以查询user_errors
或all_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识别为查询,语句,控制循环等的任何东西的开头,所以它放弃了。