易截截图软件、单文件、免安装、纯绿色、仅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


相关问答:

csv文件转换成sql导入到数据库,没有数据为何?

执行的顺序:
1)文件浏览框(选择文件使用)
选择好文件后
点击一个导入按钮的时候 ,把上面上传框里的csv文件以一个ID为文件名,上传到**/**文件夹下
2)读取这个文件夹下的csv的文件,转换成sql
3 ......

jsp链接sql2000的疑问?



type Exception report


message

description The server encountered an internal error () that prevented it from fulfilling this request.

exception

org.apache.jas ......

Asp+sql server问题 - Web 开发 / ASP

我一个项目,有个插入操作,具体是这样的:
我有进货信息表。在出货时选择相应的进货信息,输入数量,选择部门后,点保存按钮,由于网络延时,点一下没有反映,于是用户就又点一下,导致一次插入了两条记录:
例: ......

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

假设table01 中有 以下资料
emp_no emp_name
------- ------------
0001 TOM
0002 JOHN
0003 MARY
常用电话 
而我们要得到以下的OUTPUT (或是各种其他的output)
0001,TOM
0002,JOHN ......
© 2009 ej38.com All Rights Reserved. 关于E健网联系我们 | 站点地图 | 赣ICP备09004571号