存储过程错误:子查询返回多于 1 行

发布于 2024-10-05 14:35:26 字数 1346 浏览 0 评论 0原文

我正在尝试创建一个存储过程,但出现错误: Subquery returns more than 1 row for the below query 。这可以使用游标来完成,但是有没有其他方法可以在不使用游标的情况下直接在存储过程中运行此查询,因为有多个这种类型的查询,我需要在多个表的存储过程中添加这些查询。

查询:-

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
); 

I am trying to create a stored procedure but giving me an error: Subquery returns more than 1 row for the below query . This could be done using cursors but are there any other ways to directly run this query in stored procedures without using cursors since there are multiple queries of this type which i need to add in stored procedure for multiple tables.

Query:-

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);

But this Query Works for multiple field:-

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
); 

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(4

会傲 2024-10-12 14:35:26

在子查询中添加 Limit 子句。

Add Limit clause in your sub query.

没有伤那来痛 2024-10-12 14:35:26

向子查询的 WHERE 子句添加更多术语以将其缩减为一条记录,或者向该子查询添加一个 LIMIT 子句。

Add more terms to your subquery's WHERE clause to bring it down to one record, or add a LIMIT clause to the same.

情栀口红 2024-10-12 14:35:26

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

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

I don't think you need a subquery here at all. You can reference multiple tables directly in the UPDATE query:

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

一抹淡然 2024-10-12 14:35:26

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

感谢大家的帮助...

Problem solved...
for the subquery (SELECT Statement), alias was missing for patent_uid which lead to this error.
After entering the table name as alias,it started working properly inside stored procedure..

Thanks Guys for your kind help...

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文