• Oracle高级查询,事物,过程及函数


    数值函数

    数值 abs,ceil,floor,round,trunc字符串 instr,substr

    SQL>SELECT 'ABS':'|| ABS(-12.3) FROM DUAL;
    

    运行结果:

    ABS:12.3

    SQL>SELECT 'CEIL'||CELI(5.3) FROM DUAL;
    SQL>SELECT 'CEIL'||CELI(-5.3) FROM DUAL;
    SQL>SELECT 'CEIL'||CELI(5) FROM DUAL;

    运行结果:
    CEIL:6
    CEIL:-5
    CEIL:5

    SQL>SELECT 'FIOOR'||FIOOR(5.3) FROM DUAL;
    SQL>SELECT 'FIOOR'||FIOOR(-5.3) FROM DUAL;
    SQL>SELECT 'FIOOR'||FIOOR(5) FROM DUAL;
    

    运行结果:

    CEIL:5
    CEIL:-6
    CEIL:5

     

    SQL>SELECT 'ROUND'||ROUND(1346.1233,0) FROM DUAL;
    SQL>SELECT 'ROUND'||ROUND(1546.1233,-3) FROM DUAL;
    SQL>SELECT 'ROUND'||ROUND(1346.1233,3) FROM DUAL;
    

    运行结果:

    ROUND:1346
    ROUND:2000
    ROUND:1346.1

     

    SQL>SELECT 'TRUNC'||TRUNC(1346.1233,0) FROM DUAL;
    SQL>SELECT 'TRUNC'||TRUNC(1546.1233,-3) FROM DUAL;
    SQL>SELECT 'TRUNC'||TRUNC(1346.1233,2) FROM DUAL;
    

    运行结果:

    ROUND:1346
    ROUND:1000
    ROUND:1346.12


    字符函数
    字符型LOWER(CHAR)转化为小写
    UPPER(CHAR)转化为大写
    LENGTH(CHAR)返回字符串长度
    LTRIM(CHAR[,SET])去掉char中的set
    REPLACE替换
    LTRIM 去掉左空格
    RTRIM 去掉右空格
    SUBSTR截取
    转换
    to_number() to_date() to_char() NVL() NVL2(),
    SQL>SELECT 'to_number':'|| to_number('2000.22','999d9999') FROM DUAL;
    运行结果:
    to_number:2000.22
    SQL>SELECT 'to_date':'|| to_date(sysdate,'dd-mm-yy') FROM DUAL;
    运行结果:
    to_date:13-12-13
    SQL>SELECT 'to_char':'|| o_char('12-13-13','mm-dd-yy') FROM DUAL;
    运行结果:
    to_char:2013-12-13
    SQL>SELECT 'NVL':'|| NVL(COMM,0) FROM SCOTT,EMP WHERE EMPNO=7369;
    运行结果:
    to_char:0
    SQL>SELECT 'NVL2':'|| NVL2(COMM,0,1) FROM SCOTT,EMP WHERE EMPNO=7369;
    运行结果:
    to_char:1

    时间函数
    add_months months_between
    分组函数
    min max avg sum count
    分析函数
    row_number() over(order by 列) ,
    多表查询
    操作符 UNION(补) UNION ALL(并) INTERSECT(交) MINUS(差)


    内,外连接 子查询 自连接 联合查询
    内连接
    select dept.deptno,dname,ename from scott.dept,scott.emp where dept.deptno=emp.deptno;
    自连接
    select manager.ename from scott.emp manager scott.emp worker where manager.deptno=worker.mgr and worker.ename='SMITH';
    内连接/外链接
    select table1.column,table2.column from table1[inner|left|right|full]join table2 on table1.column1=table2.column2;

    事务
    (ACID) saveppoint a commit(提交)、rollback(滚回去):
    只要涉及到数据的增、删、改就会产生事物,事物要么执行提交,要么全部失败。
    执行commit之后会释放在会话中所有的行和表锁。一旦执行就不能用rollback恢复。
    自动提交事物:执行DDL(create table ,alter table ,drop table )、DCL(grant ,revoke)和退出SQL*plus时。

      事物的ACID属性:原子性,一致性,隔离性,持久性

  • 相关阅读:
    C++ calculate the time cost in 100 nanoseconds precision
    C++ append file via ofstream
    WCF Server Error in '/' Application.
    Webclient "The operation has timed out" and override webclient with customized timeout
    WPF implement SelectedCommand in MVVM via Interaction.Triggers
    将EDGE浏览器首页中的hao123删除的方法--干净的界面
    PHP 获取当前时间的下一个整点时间
    微信小程序添加空格
    为什么upload下的图片不存在,会报模块不存在的错误
    lnmp环境搭建
  • 原文地址:https://www.cnblogs.com/yangshuaigg/p/3494858.html
Copyright © 2020-2023  润新知