oracle基础之CUSD

*、oracle将一个表中的字段值更新成为另一个表中的字段值(以下三种灵活运用)

demo1 :
    update c_a i set i.photo = (select ppp.ppp
    from ppp where ppp.id = i.id)
    where i.id in (--重点语句
    select ppp.id
    from ppp );
demo2 :
    update P_TEMP fd set fd."f_id" = 
    (select fs."aimId" from P_S fs where fs."sourceId" = FD."f_id") ;

demo3 :
    update table t set t.col = 一个确定的值
    where t.id in (
     select e.id from table1,table2.... where...--结果集
    );
demo4 :
    update table t set t.ss = 一个确定的值
    where exist (
       select 1 --如果存在结果那么返回1否则说明该条数据不符合要求
       from table1,table2.....where ...
       and t.id = *.id--判断当前数据的ID信息是否存在内层数据集里
       and .....
    );

*、oracle从已存在的表中取数据并插入另一个表中

对于表字段相同
insert into table_name select * from table_n;
对于表字段不相同
insert into table_name(f1,f2,f3) select f1,f2,f3 from table_n;

*、oracle普通字段转clob

--第一步:添加一个clob类型的字段
alter table aimTable add (tempClobColName clob);
--第二部:将原来字段的值拷贝到新建的clob字段
update aimTable a set a.tempClobColName = a.simpleColName ;
第三步:删除原来的字段
--alter table aimTable drop column simpleColName;
第四步:将新建的clob字段的名字修改为原来的字段的名字
--alter table aimTable rename column tempClobColName to simpleColName;
第五步:提交
commit;

*、oracle函数之replace     

update tablename set colname = replace(colname,'souce','aim');

*、oracle常用之having多个条件

select sno from score group by sno having max(xx) > 99 and min(9) < 0;

*、oracle查询顺序不是我最初以为的那样

http://blog.csdn.net/skyxmstar/article/details/54345965

猜你喜欢

转载自lbovinl.iteye.com/blog/2333673