MySQL错误1172-结果包含多行 [英] MySQL Error 1172 - Result consisted of more than one row

查看:812
本文介绍了MySQL错误1172-结果包含多行的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在存储过程中运行查询时,我从MySQL收到此错误:

I'm getting this error from MySQL when running a query inside a stored procedure:

错误代码:1172 结果由多于一行组成

Error Code: 1172 Result consisted of more than one row

我了解错误:我正在执行SELECT (...) INTO (var list),因此要求查询返回单行.当我使用LIMIT 1SELECT DISTINCT时,错误消失了.

I understand the error: I'm doing a SELECT (...) INTO (var list), and thus the query is required to return a single row. When I use LIMIT 1 or SELECT DISTINCT, the error goes away.

但是:当我手动运行原始查询(没有LIMITDISTINCT)时,它确实返回了一行.所以我怀疑我可能碰到了一个MySQL错误.有人知道会发生什么吗?

However: when I run the original query manually (without LIMIT or DISTINCT), it does return a single row. So I'm suspecting I may have bumped into a MySQL bug. Does anyone know what could be happening?

编辑

我正在按要求发布SQL.以下划线开头的所有内容都是在过程内部早先声明的变量.测试时,我用引起问题的记录的ID替换_cd_pai_vc.

I'm posting the SQL as requested. Everything that starts with an underscore is a variable declared earlier inside the procedure. When I test it, I'm replacing _cd_pai_vc with the ID for the record that is causing the problem.

SELECT  a.valor,    IFNULL(p.valor, 0), fn_cd2alias(ra.cd_registro),    fn_cd2alias(IFNULL(p.valor,0))
INTO    _valor,     _cd_pai_vc,         _alias_verbete,                 _alias_pai
FROM dados_registros ra
    INNER JOIN dados_varchar255 a
    ON a.cd_registro = ra.cd_registro
        AND a.fl_excluido = 0
        AND a.alias = 'vc-verbetes-termo'
    LEFT OUTER JOIN dados_registros rp
        INNER JOIN dados_int p
        ON p.cd_registro = rp.cd_registro
            AND p.fl_excluido = 0
            AND p.alias = 'vc-remissoes-termo referenciado'
        INNER JOIN dados_int pt
        ON pt.cd_registro = rp.cd_registro
            AND pt.fl_excluido = 0
            AND pt.alias = 'vc-remissoes-tipo remissao'
            AND fn_cd2alias(pt.valor) = 'hierarquica'
    ON ra.cd_registro = rp.cd_entidade
        AND rp.fl_excluido = 0
        AND fn_cd2alias(rp.cd_modulo) = 'vc-remissoes'
WHERE ra.cd_registro = _cd_pai_vc 
    AND ra.fl_excluido = 0;

推荐答案

我遇到了类似的问题,当我放置表别名时,它就像一个魅力.

I had the similiar issue and when I put table alias it worked like a charm.

SELECT t.tax_amount,t.tax_percentage FROM nepse_tax t

这篇关于MySQL错误1172-结果包含多行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆