oracle基础之CUSD

本文介绍了Oracle数据库中一些实用的SQL技巧,包括如何更新表中的字段值为另一表中的值、从现有表中选择数据并插入到另一表、普通字段转换为CLOB类型的方法、使用REPLACE函数替换字符串以及HAVING子句的多条件使用等。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

*、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.youkuaiyun.com/skyxmstar/article/details/54345965

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值