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谢谢各位的解答!!!
用惯了sql server,刚学oracle谢谢各位的解答!!!
解决方案 »
- 虛擬字段
- 把soctt的密码给忘记了 怎么修改啊 各位高人?
- 创建触发器时报ORA-04098: 触发器 'DANNY.DE_TRI' 无效且未通过重新确认的错
- 请问oracle中怎样删除条件是日期型的一行记录
- 如何更新oracle数据库中的时间类型字段
- 如何列出所有月份
- oracle触发器中使用自治事务的问题
- 请问一个存储过程的问题
- Oracle中的触发器与存储过程在每次服务器重启后都变动红色无效状态,必须在触发器与存储过程上进行编译才能变成正常有效状态。请问各位如
- 有谁知道oracle9i在p4机器上安装是否有什么文件需要修改?
- 同样的sql语句为什么9i与10g的计算结果不一样?
- oracle中写function的问题!
====>>>
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是不一样的
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);这还是会报错:单行子查询返回多余一个行
不为空的可由下面的到:
(select distinct fields,fieldsnames,selecttype from T_search where fields is not null)
例如fieldsnames fields fieldsnames
1 空 空
1 wwe ee
1 rr tt这样的话 fieldsnames为1的且fields 不为空的有两条 我应该用哪条去更新哪
1 rr tt
没有这种情况
---------- ---------- ----------
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
若是你更新后结果不对的话,说明你的数据有问题,也就是不唯一 或者有其他情况