存储过程错误:子查询返回多于 1 行
我正在尝试创建一个存储过程,但出现错误: 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
在子查询中添加 Limit 子句。
Add Limit clause in your sub query.
向子查询的
WHERE
子句添加更多术语以将其缩减为一条记录,或者向该子查询添加一个LIMIT
子句。Add more terms to your subquery's
WHERE
clause to bring it down to one record, or add aLIMIT
clause to the same.我认为你根本不需要在这里使用子查询。您可以直接在 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
问题解决了...
对于子查询(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...