【问题标题】:stored procedure error:Subquery returns more than 1 rows存储过程错误:子查询返回超过 1 行
【发布时间】:2010-12-03 07:13:30
【问题描述】:

我正在尝试创建一个存储过程,但给了我一个错误:子查询为以下查询返回超过 1 行。这可以使用游标来完成,但是是否有任何其他方法可以在不使用游标的情况下直接在存储过程中运行此查询,因为我需要在存储过程中为多个表添加多个此类查询。

查询:-

UPDATE ipcc_patent_ipc_class
SET assignee_type = (
SELECT IF(ipcc_patent_master.assignee_type='$ipcc_config_param[0]',$ipcc_config_value[0],IF(ipcc_patent_master.assignee_type='$ipcc_config_param[1]',$ipcc_config_value[1],null))
FROM ipcc_patent_master
WHERE ipcc_patent_ipc_class.patent_id = patent_uid);

但此查询适用于多个字段:-

UPDATE ipcc_patent_ipc_class
SET geographies_id=(
  SELECT ipcc_geographies.geographies_uid
  FROM ipcc_patent_master,ipcc_geographies
  WHERE ipcc_patent_master.geographies = ipcc_geographies.geographies
  AND ipcc_patent_ipc_class.patent_id = ipcc_patent_master.patent_uid
),
jurisdictions_id =(
  SELECT ipcc_jurisdictions.jurisdisctions_uid
  FROM ipcc_patent_master,ipcc_jurisdictions
  WHERE ipcc_patent_master.jurisdictions = ipcc_jurisdictions.jurisdictions
  AND ipcc_patent_ipc_class.patent_id = ipcc_patent_master.patent_uid
),
country_code_id =(
  SELECT ipcc_country_code.country_code_uid
  FROM ipcc_patent_master,ipcc_country_code
  WHERE ipcc_patent_master.country_code= ipcc_country_code.country_code
  AND ipcc_patent_ipc_class.patent_id = ipcc_patent_master.patent_uid
); 

【问题讨论】:

  • 您能否引用确切的错误以及您尝试创建 SP 的确切 SQL?

标签: php mysql stored-procedures mysql-error-1242


【解决方案1】:

在子查询中添加限制子句。

【讨论】:

  • Limit 没有解决问题,因为通过 php 脚本或 mysql 查询浏览器运行时的相同查询通过更新多行给出了所需的输出,但是当添加到存储过程中时会出现上述错误。
  • 你是在更新还是选择中设置了限制?我怀疑是后者。
【解决方案2】:

在子查询的 WHERE 子句中添加更多字词以将其缩减为一条记录,或者在同一条记录中添加 LIMIT 子句。

【讨论】:

    【解决方案3】:

    我认为您根本不需要子查询。您可以直接在 UPDATE 查询中引用多个表:

    http://dev.mysql.com/doc/refman/5.0/en/update.html

    【讨论】:

    • 我在选择查询中添加了一个条件。使用更新怎么可能?
    【解决方案4】:

    问题解决了... 对于子查询(SELECT 语句),导致此错误的patent_uid 缺少别名。 输入表名作为别名后,它开始在存储过程中正常工作..

    感谢大家的热心帮助...

    【讨论】:

      猜你喜欢
      • 2021-01-27
      • 1970-01-01
      • 2011-12-13
      • 2023-03-21
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多