gpt4 book ai didi

sql - ORA-00932(数据类型不一致 : expected - got CLOB) error that I do not understand

转载 作者:行者123 更新时间:2023-12-02 13:12:27 27 4
gpt4 key购买 nike

我从这样的查询开始:

    SELECT A.*
FROM TABLE_A A
INNER JOIN TABLE_B B
ON A.YEAR = B.YEAR
WHERE A.ID IN (SELECT ID FROM TABLE_B)

上面的查询给了我重复的记录,因此我添加了 DISTINCT 关键字,如下所示:

    SELECT DISTINCT A.*
FROM TABLE_A A
INNER JOIN TABLE_B B
ON A.YEAR = B.YEAR
WHERE A.ID IN (SELECT ID FROM TABLE_B)

第二个查询给了我以下错误:

ORA-00932: inconsistent datatypes: expected - got CLOB

  1. 00000 - "inconsistent datatypes: expected %s got %s"

我最终通过将 WHERE 子句中的条件移动到 INNER JOIN 来纠正查询并消除重复记录,如下所示:

    SELECT A.*
FROM TABLE_A A
INNER JOIN TABLE_B B
ON A.YEAR = B.YEAR
AND A.ID = B.ID

我只是不明白为什么第二个查询不起作用。为什么在此处添加 DISTINCT 关键字会突然导致出现问题?

最佳答案

这不是一条特别有启发性的错误消息,但这是因为the restrictions on LOBs ,其中有:

  • You cannot specify LOB columns in the ORDER BY clause of a query, the GROUP BY clause of a query, or an aggregate function.

  • You cannot specify a LOB column in a SELECT... DISTINCT or SELECT... UNIQUE statement or in a join. However, you can specify a LOB attribute of an object type column in a SELECT... DISTINCT statement, a query that uses the UNION, or a MINUS set operator if the object type of the column has a MAP or ORDER function defined on it.

您遇到了其中的第二个,但这里有时也会出现第一个。

您可以使用以下内容来伪造相同的情况:

SQL> select distinct col from (select to_clob('test') as col from dual);

ERROR at line 1:
ORA-00932: inconsistent datatypes: expected - got CLOB

如果您仅列出非 CLOB 列,则可以使用 distinct,而不是使用 A.*,后者包含来自 的 CLOB 列表_a

You can work around this ,但更正查询以消除重复项是正确的做法。必须在查询中添加 distinct 通常表明出现了问题,并且您正在修复症状而不是原因。

关于sql - ORA-00932(数据类型不一致 : expected - got CLOB) error that I do not understand,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/43637438/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com