Oracle 问题小结

1.级联更新

//例子1
update (select a.name aname,b.name bname from test1 a,test2 b where 
 a.no=b.no) set aname=bname; 
//例子2
update test1 a set name=(select name from test2 b where a.no=b.no) where 
 exists(select name from test2 b where a.no=b.no); 
2.使用oracle中的Replace()方法
select  Replace(字段名, '被替换内容', 替换内容) from t_pianqu
3。字符串拼接(级联更新、Replace()方法、拼接)
select b.序号,a.油站名称
  from t_xitongwaijiayouzhan a, t_pianqu b
 where a.油站名称 like '%'||Replace(b.片区名称, '片区', null)||'%'
综合上面三个总示例
update t_xitongwaijiayouzhan h
   set h.片区序号 =
       (select distinct(d.序号) from (select b.序号,a.油站名称
  from t_xitongwaijiayouzhan a, t_pianqu b
 where a.油站名称 like '%'||Replace(b.片区名称, '片区', null)||'%') d where d.油站名称=h.油站名称)
4.有则更新无则插入
MERGE INTO t_xitongwaijiayouzhan dest
USING t_systemoutstation sources
ON (dest.油站代码 = sources.油站代码)
WHEN MATCHED THEN
  UPDATE
     SET dest.油站名称 = sources.油站名称,
         dest.油站地址 = sources.油站地址,
         dest.状态标识 = 3
WHEN NOT MATCHED THEN
  INSERT
  VALUES
    ('',
     sources.公司代码,
     sources.地市公司,
     sources.油站代码,
     sources.油站名称,

     sources.状态标识
);
posted @ 2010-06-03 18:18  幕三少  阅读(378)  评论(0编辑  收藏  举报