Oracle PL-SQL 中定义不明确的列

发布于 2024-12-28 06:03:48 字数 492 浏览 1 评论 0原文

我试图在不同的表上选择多行,但无论我做什么都无法让它工作。 我收到此错误:

Error(14,1): PL/SQL: ORA-00918: column ambiguously defined

代码(注意,这是触发器的一部分,这就是为什么有 :new):

SELECT brw.borage, bt.agelower, bt.ageupper
INTO borAge, minAge, maxAge
FROM Borrower brw, BookTitle bt
  INNER JOIN BookCopy bc ON  :new.bcID = bc.bcID
  INNER JOIN BookTitle bt ON bt.isbn = bc.isbn

注意:BookTitle 只有一个ageLower 和ageUpper 列。除了 borAge、minAge 和 maxAge 之外,也没有其他减法。

I'm trying to select multiple rows over different tables but I can't get it to work whatever I do.
I get this error:

Error(14,1): PL/SQL: ORA-00918: column ambiguously defined

Code (Note, this is part of a trigger, that's why there's the :new):

SELECT brw.borage, bt.agelower, bt.ageupper
INTO borAge, minAge, maxAge
FROM Borrower brw, BookTitle bt
  INNER JOIN BookCopy bc ON  :new.bcID = bc.bcID
  INNER JOIN BookTitle bt ON bt.isbn = bc.isbn

NOTE: BookTitle has only ONE ageLower and ageUpper column. There's no declerations apart from borAge, minAge and maxAge either.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

旧人哭 2025-01-04 06:03:48

问题是你有两次相同的别名,试试这个:

SELECT brw.borage, bt.agelower, bt.ageupper
INTO borAge, minAge, maxAge
FROM Borrower brw, BookTitle bt
  INNER JOIN BookCopy bc ON  :new.bcID = bc.bcID
  INNER JOIN BookTitle bt2 ON bt2.isbn = bc.isbn

但这可以给你比预期更多的结果,因为你把 BookTitle 表放在 FROM 部分。


我认为只有这可能才是您真正需要的:

SELECT brw.borage, bt.agelower, bt.ageupper
INTO borAge, minAge, maxAge
FROM Borrower brw
  INNER JOIN BookCopy bc ON  :new.bcID = bc.bcID
  INNER JOIN BookTitle bt ON bt.isbn = bc.isbn

Tre problem is that you have two times the sames alias, try this:

SELECT brw.borage, bt.agelower, bt.ageupper
INTO borAge, minAge, maxAge
FROM Borrower brw, BookTitle bt
  INNER JOIN BookCopy bc ON  :new.bcID = bc.bcID
  INNER JOIN BookTitle bt2 ON bt2.isbn = bc.isbn

but this can give you more results then expected, because you put BookTitle table on the FROM part.


I think that only this might be what you really need:

SELECT brw.borage, bt.agelower, bt.ageupper
INTO borAge, minAge, maxAge
FROM Borrower brw
  INNER JOIN BookCopy bc ON  :new.bcID = bc.bcID
  INNER JOIN BookTitle bt ON bt.isbn = bc.isbn
橘和柠 2025-01-04 06:03:48

您定义 BookTitle bt 两次。

You define BookTitle bt twice.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文