• 常用的sql语言基础(1)



    数据文件:存放数据不能随便删除
    查看数据方式:select name from v$datafile;
    select file_name from dba_data_file;

    控制文件:是一个二进制文件.ctl形式存在
    查看控制文件的方式:
    select name from v$controlfile;
    show parameter congtrol_flie;

    临时文件:存放临时数据的
    查看方式 :select name from v$tempfile;
    select file_name from dba_temp_file;

    日志文件:对数据库的操作信息的记录,已log的形式存在,分为联机重做日志文件和归档日志文件。
    联机重做日志文件:强制记录force_looging 正好记录looging 不记录no_looging

    查看方式:
    select
    数据库的三种状态:open,mont挂载,close;
    查看数据库是否处于归档状态:archive log list;
    归档模式和非归档模式切换:1.关闭数据库:shutdown immediate;
    2.登录空闲历程并打开数据库:conn /as sysdba; startup mount;
    3.变为归档模式:alter datbase aarchivelog;


    /*基本查询*/
    查询格式:select 列名 from 表名;
    --查询系统中的表:select table_name from user_tables;
    --查询系统的时间:select sysdate from dual;//从dual中能查询所有想要的系统信息,被称为万能表;
    select user from dual;
    --查看表中所有的信息:select * from emp;
    --查看特定的列名:select empno,ename from emp;
    --给列起别名:as可有可无,数字加双引号
    select empno 编号,ename 姓名,job 工作 from emp;
    select empno as 编号 from emp;
    select empno "1" from emp;
    select empno as "1" from emp;
    --限定条件where:
    select * from emp where sal>200; select * from emp where sal>200 and/or sal<300;
    --intersect交集and:
    select * from emp where sal>200 intersect select * from emp where sal<300;
    --union,union all,or, union等同于all;union去除了重复记录,union all 没有去除重复记录,运行效率高
    --布尔操作符,排列顺序 not and or
    --模糊查询: %表示任意个字符;_表示单个字符
    select * from emp where ename like '%A%';//姓名中有A的
    select * from emp where ename like '_A%';//第二个字母是A的

    --排序order by:
    select * from emp order by sal asc;//升序排列默认,desc降序排列
    select ename,empno,sal,job from emp order by 3;// 对第3列进行排序
    select ename 姓名,empno 编号 from emp order by 姓名;
    --限定范围:
    select * from emp where sal between 200 and 300;//表示范围
    select * from emp where sal in('200','300');//表示具体的值
    --去除重复数据:
    select distinct job from emp;
    --空值,查询空值用null,空值处理用nvl,空值与任何值进行逻辑运算都为空;空值默认最大
    select * from emp where comm is null;
    select nvl(comm,0),ename from emp;
    select sal+nvl(comm,0),ename from emp;

    /*标量函数*/
    --字符函数
    --大写转换成小写,用lower:
    select lower('DLDSFS') from dual;
    --小写转换成大写,用upper:
    select upper('dfs') from dual;
    --首字母大写用initcap
    select initcap('sdfd') from dual;
    --关联字符串,concat(关联两个字符串)或者||(关联多个字符串)
    select concat('hp','BI') from dual; select 'hp'||'BI'||'bd'||'dd' from dual;
    --截取字符串,substr,从0开始截取和送1开始截取效果一样表示位置,第三位表示截取长度
    select substr('dsfsd',0,3) from dual;//截取前三位
    select substr('sdfds',3,3) from dual;
    select substr('sdfds',-3,3) from dual;//倒着数开始截取
    --求字符串长度,length
    select length('dfddf') form dual;

    ----以首字母大写的方式显示所有员工的姓名
    select upper(substr(ename,1,1))||lower(substr(ename,2)) from dual;
    select concat(upper(substr(ename,1,1)),lower(substr(ename,2)) from dual;
    ----要求截取员工姓名的后三个字符
    select substr(ename,-3) from dual;
    --替换字符串replace,2为要替换的字符,3为替换后的字符
    select replace('hukdlla','kd','mn') from dual;//将kd替换成mn
    select replace('ttttdf','tdf','eee') from dual;
    --消除左右空格或字符串,trim; ltrim是消除左面的字符或者空格,rtrim是消除右面。。。。
    select ltrim(both 'a' from 'aaaaukkaaa') form dual;
    select ltrm('aaaaadd','a') from dual;
    select rtrim('aaaakaaa','a') from dual;
    select ltrim(' dfdsf') from dual; select rtrim('sdfds ') from dual;
    select trim(' dsfdsf ') from dual;
    --lpad在左边添加字符到指定的长度;rpad在右边添加字符到指定的长度,(a,b,c),b表示添加的长度,c要添加的字符
    select lpad('dsff',12,'a') from dual;
    select rpad('dsff',12,'a') from dual;

    --数值函数
    --四舍五入round
    select round(123.43) from dual;
    select round(123.43,2) from dual;//保留2为小数
    --截断小数位用trunc
    select trunc(123.43) from dual;
    select trunc(123.43,1) from dual;//保留1位小数
    select trunc(123.43,2) from dual;//保留2为小数
    --取余数mod
    select mod(10,3) from dual;

    --日期函数
    --查询系统时间
    select sysdate from dual;
    --last_day表示当前时间月末最后一天的这个时间
    select last_day(sysdate) form dual;
    --months_between,表示两个时间的月份数
    select months_between(sysdate,hiredate) from emp;
    --next_day,表示当前日期开始的下一个星期几
    select next_day(sysdate,'星期三') from dual;

  • 相关阅读:
    统计学习方法 学习笔记(八):k 近邻法
    统计学习方法 学习笔记(七):拉格朗日对偶性
    统计学习方法 学习笔记(六):序列最小最优化算法SMO
    统计学习方法 学习笔记(五):支持向量机(下)
    统计学习方法 学习笔记(四):支持向量机(中)
    统计学习方法 学习笔记(三):支持向量机(上)
    统计学习方法 学习笔记(二):感知机
    CUDA npp运动检测模块性能测试
    CUDA H624解码性能测试
    利用GPU改善程序性能的一点心得
  • 原文地址:https://www.cnblogs.com/bbker/p/5646719.html
Copyright © 2020-2023  润新知