oracle 中的sql 语句

1、update 表名 set 表字段=(select 另一个表中的相同字段 from 另一个表表名 where 表.字段=另一个表.字段) where  表.字段=?

例子:将某个表中的更新到另一个表中

update psp_model  m set m.mp_id=(select mp_id from psp_c_mp mp where p.mp_no=mp.mp_no) where  m.mp_no=?

2、insert into 表名  m(mp_id,mp_name,mp_no,org_id)select distinct m.mp_id,mp_name,mp_no,org_id from另一个表 where t条件 and not exists (select mp_no from 表名 mp where  m.mp_id=mp.mp_id)

例子:将一个表中的数据插入到另一个表中

 insert into psp_mp (mp_id,mp_name,mp_no,org_id) select distinct m.mp_id,m.mp_name,m.mp_no,m.org_id  from psp_model  m  where  is_monitor =? and  distline_no =? and m.mp_no is not null and not exists (select mp_no from psp_mp mp where m.mp_id=mp.mp_id)

3、update 表名 set 表字段= 另一个字段 where 条件

例子:更新一个表中的字段到另一个字段

update  psp_model m  set mp_id=mp_no where is_monitor=? and distline_no=?

4、delete from  表名 where 条件

例子: 根据条件删除表中的额数据

delete  from psp_model where disline_no=?

5、truncate table 表名

例子: 删除表中所有的数据

truncate table psp_model

6、decode 的使用

例子:判断的作用

decode(mp_id,null,mp_no,mp_id) 如果 mp_id 为空是mp_no 不为空 mp_id

猜你喜欢

转载自www.cnblogs.com/chengxuyuanIng/p/10514654.html