易截截图软件、单文件、免安装、纯绿色、仅160KB

oracle 替换数据的sql该怎么写 - Oracle / 开发

有两张表
  A B
  id hyid hyid newid
  1 2 2 A
  2 3 3 B
  现在要将a表的hyid换成b表的newid,请注意a表中的hyid不是唯一的
  oracle中该 怎么处理


merge into a using b 
on (a.hyid=b.hyid)
when matched then
update set a.hyid=b.newid  
a.hyid 在on句中,不能修改

我另外在a表中弄了一条数据hy和hyid保持一致
并且因为a表中的hyid不是唯一的,结果错误无法获得稳定行
update a set hyid=(
  select newid from b where hyid=a.hyid)
where exists(
  select 1 from b where hyid=a.hyid)

SQL code:
update a set a.hyid=(select newid from b where b.hyid=a.hyid and rownum<2)
and exists (select 1 from b where b.hyid=a.hyid);


引用
update a set hyid=(
select newid from b where hyid=a.hyid)
where exists(
select 1 from b where hyid=a.hyid)


1楼正解,用merge无法修改

看样子不错 ,不过还是修改不了,错误:单行子查询返回多个行
 

--where rownum=1限制下

update a set hyid=(
select newid from b where hyid=a.hyid where rownum=1)
where exists(
select 1 from b w


相关问答:

Oracle离线访问---求助 - Oracle / 基础和管理

大家好,我现在把oracle服务器上面的原始文件,下载到本机了.我想在本机访问数据库怎么设置啊.是不是类似可以建立一个什么虚拟服务器来实现.请大家出出主意
引用
    大家好,我现在把oracle服务器上面 ......

oracle spatial空间函数出错 - Oracle / 高级技术

在执行包的时候引用oracle spatial空间函数出错,出错情况如下
Errors in file
/user/oracle/app/oracle/admin/grid/udump/grid1_ora_143768.trc: ORA-29902:
error in executing ODCIIndexStart() routine ORA-0 ......

[原创] ORACLE 连接字串 - Oracle / 非技术区

假设table01 中有 以下资料
emp_no emp_name
------- ------------
0001 TOM
0002 JOHN
0003 MARY
常用电话 
而我们要得到以下的OUTPUT (或是各种其他的output)
0001,TOM
0002,JOHN ......

请教SQLSERVER的两个问题 - MS-SQL Server / 疑难问题

1。怎样使xp_cmdshell能完整输出超过255个字符的字符串。
2。select 时,检索速度是与from后的 TABLE顺序有关,还是与where条件的顺序有关(TABLE数据多少 )
在系统属性设定里有个选项,可以修改单字段输出字数限制. ......

oracle 10g data guard - Oracle / 基础和管理

做玩data guard 后
在Primary服务器 执行 
SQL>SELECT SEQUENCE#,APPLIED from V$ARCHIVED_LOG ORDER BY SEQUENCE#;
 SEQUENCE# APP
---------- ---
  13 NO
  13 YES ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号