免费注册 查看新帖 |

Chinaunix

  平台 论坛 博客 文库
最近访问板块 发新帖
查看: 2320 | 回复: 9
打印 上一主题 下一主题

大家帮我看一下这个语句为什么会报错 [复制链接]

论坛徽章:
0
跳转到指定楼层
1 [收藏(0)] [报告]
发表于 2005-07-28 22:56 |只看该作者 |倒序浏览
把同一个表中符合某个条件的同一字段的值赋给另外一个元素

update table set table.name=(select table.name from table where 条件) where 条件

论坛徽章:
0
2 [报告]
发表于 2005-07-29 13:51 |只看该作者

大家帮我看一下这个语句为什么会报错

-360    Cannot modify table or view used in subquery.

The UPDATE, INSERT, or DELETE statement uses data taken from the same table
in a subquery. This action is not allowed because of the danger of getting
into an endless loop. Select the input data into a temporary table first,
and then refer to the temporary table in the UPDATE or INSERT statement.

论坛徽章:
0
3 [报告]
发表于 2005-07-29 17:54 |只看该作者

大家帮我看一下这个语句为什么会报错

table.name=(select table.name from table where 条件) 这里选出的不是唯一的一条记录,而是记录集合

论坛徽章:
0
4 [报告]
发表于 2005-07-30 20:32 |只看该作者

大家帮我看一下这个语句为什么会报错

做个实验
一.建两张测试表test1,test2
  create table test1
  (
    co1 char(1)
  );
  
  create table test2
  (
    co1 char(1)
  );

二.
都插入9条记录
1|
2|
3|
..
9|

三.实验:
update test1
set co1=(select co1 from test1 where co1=1)
where co1=5

报错
360: Cannot modify table or view used in subquery.  
------------------------------
update test1
set co1=(select co1 from test2 where co1=1)
where co1=5
select * from test1;

co1

1  
2
3
4
1
6
7
8
9
说明不是集合的问题,只要注意让条数对上就好了
-----------------------------

论坛徽章:
0
5 [报告]
发表于 2005-07-31 22:15 |只看该作者

大家帮我看一下这个语句为什么会报错

[quote]原帖由 "yyiiasc"]table.name=(select table.name from table where 条件) 这里选出的不是唯一的一条记录,而是记录集合[/quote 发表:

都给了条件,只有一条记录。

论坛徽章:
0
6 [报告]
发表于 2005-07-31 22:17 |只看该作者

大家帮我看一下这个语句为什么会报错

原帖由 "twothings" 发表:
做个实验
一.建两张测试表test1,test2
  create table test1
  (
    co1 char(1)
  );
  
  create table test2
  (
    co1 char(1)
  );

二.
都插入9条记录
1|
2|
3|
..
9|

三.实验:
..........

你建了两张表,根据你的思路用临时表试一下。

论坛徽章:
0
7 [报告]
发表于 2005-08-01 13:35 |只看该作者

大家帮我看一下这个语句为什么会报错

原帖由 "twothings" 发表:
-360    Cannot modify table or view used in subquery.

The UPDATE, INSERT, or DELETE statement uses data taken from the same table
in a subquery. This action is not allowed because of the danger of..........

提示不是写得很清楚么,不能更改子句中引用的表

论坛徽章:
0
8 [报告]
发表于 2005-08-02 20:43 |只看该作者

大家帮我看一下这个语句为什么会报错

--------------------------------------------------------------------------------

把同一个表中符合某个条件的同一字段的值赋给另外一个元素

update table set table.name=(select distinct  table.name from table where 条件) where 条件

论坛徽章:
0
9 [报告]
发表于 2005-08-02 22:36 |只看该作者

大家帮我看一下这个语句为什么会报错

原帖由 "一把火" 发表:
--------------------------------------------------------------------------------

把同一个表中符合某个条件的同一字段的值赋给另外一个元素

update table set table.name=(select distinct  table.nam..........


不要想当然,你测试了么

论坛徽章:
0
10 [报告]
发表于 2005-08-03 09:17 |只看该作者

大家帮我看一下这个语句为什么会报错

已经用临时表的方式解决:
select * from table where 条件 into temp ftmp;
update table set table.name=(select name from ftmp)   where 条件;
您需要登录后才可以回帖 登录 | 注册

本版积分规则 发表回复

  

北京盛拓优讯信息技术有限公司. 版权所有 京ICP备16024965号-6 北京市公安局海淀分局网监中心备案编号:11010802020122 niuxiaotong@pcpop.com 17352615567
未成年举报专区
中国互联网协会会员  联系我们:huangweiwei@itpub.net
感谢所有关心和支持过ChinaUnix的朋友们 转载本站内容请注明原作者名及出处

清除 Cookies - ChinaUnix - Archiver - WAP - TOP