下面语句是什么问题,急!

splory 2007-04-04 03:29:06
update T_search set Fields=b.Fields,SelectType=b.SelectType from T_search a,(select distinct fields,fieldsnames,selecttype from T_search where fields is not null) b where a.fieldsnames=b.fieldsnames;

这语句会报错:ORA-00933 命令未正确结束

语法我感决没错阿
用惯了sql server,刚学oracle

谢谢各位的解答!!!
...全文
272 10 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
10 条回复
切换为时间正序
请发表友善的回复…
发表回复
splory 2007-04-04
  • 打赏
  • 举报
回复
那种情况就不用更新先
wangzk0206 2007-04-04
  • 打赏
  • 举报
回复
SQL> select * from a;

ID FIELD VAL
---------- ---------- ----------
1
1 2 3
2 3 4
2
2 5
SQL> update a set (field,val)=(select b.field,b.val from a b where a.id=b.id and b.field is not null
2 and a.field is null)
3 where exists(select 1 from a b where a.id=b.id and b.field is not null
4 and a.field is null);

已更新3行。

SQL> select * from a;

ID FIELD VAL
---------- ---------- ----------
1 2 3
1 2 3
2 3 4
2 3 4
2 3 4
若是你更新后结果不对的话,说明你的数据有问题,也就是不唯一 或者有其他情况
wangzk0206 2007-04-04
  • 打赏
  • 举报
回复
那有没有 fieldsnames值为1而FIELDS全部为空的

还是我给你做个测试吧

splory 2007-04-04
  • 打赏
  • 举报
回复
1 wwe ee
1 rr tt
没有这种情况
wangzk0206 2007-04-04
  • 打赏
  • 举报
回复
你的查询应该是根据这个字段fieldsnames

以这个字段分组,不为空的记录会有几条 若是多与1条我用哪条去更新哪?
例如

fieldsnames fields fieldsnames
1 空 空
1 wwe ee
1 rr tt

这样的话 fieldsnames为1的且fields 不为空的有两条 我应该用哪条去更新哪
splory 2007-04-04
  • 打赏
  • 举报
回复
我要到达的效果就是在本表中用某个字段(不为空的记录去更新其他为空的记录)
不为空的可由下面的到:
(select distinct fields,fieldsnames,selecttype from T_search where fields is not null)
wangzk0206 2007-04-04
  • 打赏
  • 举报
回复
这个错误就是我所说的要确保唯一

那说下你的需求吧 列举出例子来

splory 2007-04-04
  • 打赏
  • 举报
回复
to love_2008(love2008):
update T_search set (Fields,SelectType) = (select distinct b.fields, b.selecttype from T_search b where fieldsnames=b.fieldsnames)
where exists (select 1 from T_search b where fieldsnames=b.fieldsnames);

这还是会报错:单行子查询返回多余一个行
CathySun118 2007-04-04
  • 打赏
  • 举报
回复
oracle不支持distinct 吧
wangzk0206 2007-04-04
  • 打赏
  • 举报
回复
update T_search set Fields=b.Fields,SelectType=b.SelectType from T_search a,(select distinct fields,fieldsnames,selecttype from T_search where fields is not null) b where a.fieldsnames=b.fieldsnames;
====>>>
update T_search set (Fields,SelectType) = (select distinct b.fields, b.selecttype from T_search b where fieldsnames=b.fieldsnames)
where exists (select 1 from T_search b where fieldsnames=b.fieldsnames);
大致就是这样,确保两个字段关联后,查询是唯一的,否则会报错

具体看下ORACLE的语法,ORACLE和MSSQL是不一样的

17,140

社区成员

发帖
与我相关
我的任务
社区描述
Oracle开发相关技术讨论
社区管理员
  • 开发
  • Lucifer三思而后行
  • 卖水果的net
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧