查处a中不再b中的数据
from hz_qyhznr a, hk_jd b
where a.nbxh = b.nbxh(+) and b.nbxh is null
更新数据:
update xkz_xt_group a
set a.depid = (select t.deptid from xkz_xt_dept t where a.depid = t.gxdw)where depid in (select t.gxdw from xkz_xt_dept t where a.depid = t.gxdw);
序号:
select rownum from xb_bm_xzqh t where t.code like '33%' order by t.xh
树状结构:
查询父类ID为6的所有子类信息 select * from classinfo a start with classid=6 connect by prior classid=parentid
更新数据
update (select a.sfzh sfzh,
nvl(a.sfzh,b.sfzjhm) sfzjhm,
a.sfzjmc sfzjmc,
nvl(a.sfzjmc,'1') sfzjmc1,
a.dh dh,
nvl(a.dh,b.dhhm) dhhm,
a.dsrmc dsrmc,
nvl(a.dsrmc,b.zrr) zrr1,
a.fddbr fddbr,
nvl(a.fddbr,b.zrr) zrr,
a.jydz jydz,
nvl(a.jydz,b.zs) zs,
a.zz zz,
nvl(a.zz,b.zs) zs1,
a.xb xb,
nvl(a.xb,b.xb) xb1,
a.nl nl,
nvl2(b.nl, to_number(translate(b.nl, '0' || translate(b.nl, '#0123456789', '#'), '0')), '') nl1 --vchar类型去掉非数字类字符串
/*translate(b.nl, '0' || translate(b.nl, '#0123456789', '#'), '0')*/
from aj_lc_dsr a, hk_wzjy b,aj_lc_aj c
where a.nbxh = b.xh and a.ajbh=c.ajbh and c.ajly='20')
set sfzh = sfzjhm,
sfzjmc = sfzjmc1,
dh = dhhm,
dsrmc = zrr1,
fddbr = zrr,
jydz = zs,
zz = zs1,
xb = xb1,
nl = nl1;
Insert是T-sql中常用语句,Insert INTO table(field1,field2,...) values(value1,value2,...)这种形式的在应用程序开发中必不可少。但我们在开发、测试过程中,经常会遇到需要表复制的情况,如将一个table1的数据的部分字段复制到table2中,或者将整个table1复制到table2中,这时候我们就要使用SELECT INTO 和 INSERT INTO SELECT 表复制语句了。
1.INSERT INTO SELECT语句
语句形式为:Insert into Table2(field1,field2,...) select value1,value2,... from Table1
要求目标表Table2必须存在,由于目标表Table2已经存在,所以我们除了插入源表Table1的字段外,还可以插入常量。示例如下:
![](https://i-blog.csdnimg.cn/blog_migrate/0be121fa5b8988fbabbbc526af3b0fc0.gif)
2.SELECT INTO FROM语句
语句形式为:SELECT vale1, value2 into Table2 from Table1
要求目标表Table2不存在,因为在插入时会自动创建表Table2,并将Table1中指定字段数据复制到Table2中。示例如下: