MySQL错误1172-结果包含多个行
作者:互联网
在存储过程中运行查询时,我从MySQL收到此错误:
Error Code: 1172
Result consisted of more than one row
我理解错误:我正在执行SELECT(…)INTO(变量列表),因此需要查询才能返回单行.当我使用LIMIT 1或SELECT DISTINCT时,错误消失了.
但是:当我手动运行原始查询(没有LIMIT或DISTINCT)时,它确实返回了一行.因此,我怀疑自己可能遇到了MySQL错误.有人知道会发生什么吗?
编辑
我按要求发布了SQL.以下划线开头的所有内容都是在过程内部早先声明的变量.当我对其进行测试时,我将_cd_pai_vc替换为导致问题的记录的ID.
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;
解决方法:
我遇到了这个问题,发现当我在select语句中使用表名和列名时,甚至是简单的表名和列名都消失了.
标签:mysql,stored-procedures 来源: https://codeday.me/bug/20191201/2082493.html