• Oracle基本语句


    Oracle数据库基本语句:
    假设有表job,有4个字段JOB,SKILL,LS,ID都为varchar类型
    添加一行数据
    insert into job (JOB,SKILL,LS,ID) values ('行长','领导','1’,'1'); //为job表添加一条数据,其中job为‘行长’,skill为‘领导’,ls为’1‘,id为’1‘
    删除一行数据
    delete from job where ID = '1'; //删除job表中id为’1‘的所有数据
    去重查询
    select distinct name from job //查询表job中name字段的不重复数据
    修改一行数据
    update job set JOB=’' where ID=''; //将job表中id为''数据的job字段更新为''
    模糊查询
    select * from job where job like '%航空%'  //查询job表中job字段中含‘航空’的所有数据
    修改表名
    alter table job rename to work;   //将表job改名为work
    修改表中元素名
    alter table job rename column skill to sky; //将job表中的skill字段改为sky
    添加一个字段
    alter table job add (c varchar2(50))  //为job表添加一个varchar类型,长度为50,名称为c的字段
    删除一个字段
    alter table job drop(c)   //删除job表中名称为c的字段
    联合查询(其中nine_ans,nine_score为表名,type,score,objid,num,ans为字段名)
    select b.type, sum(b.score) as score
    from nine_ans t,nine_score b
    where t.objid='402881613a49410e013a4a8e
    7b89001e'
    and t.num=b.num
    and t.ans = b.seclection
    group by type)
    行转列 (使用pivot函数)
    select * from (select b.type, sum(b.score) as score
     
    from nine_ans t, nine_score b
    where t.objid = '402881613a49410e013a4a8e
    7b89001e'
    and 
    t.num = b.num
    and t.ans = b.seclection
    group 
    bytype)pivot(sum(score)for  type in  ('H' as H,'E'  as  E))
    用于替换字段值docode函数
    select decode(需要替换的字段名,需要替换的字段值,替换后的字段值,返回字段名) 
    as  更换字段名可以不更换
    select userid,name,sex,edu,tel,email,(select j.job from job j whereid = u.job) from userinfo u where usergroup in (select usergroupfrom admin where username like 'dm%')
  • 相关阅读:
    matplotlib 学习总结
    数据获取,解析,存储等知识的学习总结
    python学习总结
    Mybatis Plus各种查询方法
    centos启动Nginx提示nginx: [emerg] still could not bind()
    vue只能本地跨域,线上跨域要后端弄
    小程序图片懒加载
    html直接引入vue.js
    vue监听浏览器关闭
    【算法】归并排序算法的编码和优化
  • 原文地址:https://www.cnblogs.com/MedivhQ/p/4075003.html
Copyright © 2020-2023  润新知