简体   繁体   English

ORA-01422,但查询工作正常

[英]ORA-01422, but Query works fine

I'm getting absolutely crazy over this. 我对此感到非常疯狂。 I'm currently writing a trigger to change some dates around. 我目前正在编写触发器来更改一些日期。 For that I want to get a max value into a variable like so: 为此,我想将最大值放入这样的变量中:

SELECT date INTO datevar
               FROM table
               WHERE date = (SELECT MAX(date)
                                    FROM table
                                    WHERE condition = loop.condition);

The trigger always throws an ORA-01422 (Too many rows returned) on the line of this query; 触发器始终在此查询的行上抛出ORA-01422(返回的行太多)。 but when I try the query in my sqldeveloper (substituting the loop value with a number) the query works fine, with any data set (works fine = returns exactly one row). 但是,当我在sqldeveloper中尝试查询(用数字替换循环值)时,该查询可以使用任何数据集正常运行(正常=恰好返回一行)。

I tried different ways to select the max value into my var, but it's the same problem every time. 我尝试了不同的方法来将最大值选择到我的var中,但是每次都是相同的问题。 The loop works fine (when I run the trigger as stored procedure with verbose logging, I see the loop row id's and everything), but it always starts with said error without writing to the database. 循环工作正常(当我使用详细日志记录将触发器作为存储过程运行触发器时,我看到了循环行ID以及所有内容),但是循环始终以上述错误开始,而没有写入数据库。

I also scoured the web, but I didn't find anything. 我还搜索了网络,但没有找到任何东西。 I'd appreciate any ideas. 我将不胜感激。

Why would you run such a complicated query? 为什么要运行这么复杂的查询? Replace it with: 替换为:

SELECT MAX(date) INTO datevar
FROM table
WHERE condition = loop.condition;

This cannot generate such an error. 这不会产生这样的错误。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM