• oracle系列(三)表操作基础


    支持的数据类型:

    字符型
    char 定长 最大2000
    varchar2() 变长 最大4000
    clob 字符型大对象 最大4G

    数字型
    number范围 -10的38次方到10的+38次方;
    number(5,2) 一个小数,有效位5个,小数点后2个数字
    number(5) 表示一个5位的整数

    日期类型
    date
    timestamp

    二进制数据
    blob 保密性较高,存入数据库/其他情况,保持在文件服务器,数据库只存文件路径

    建表:

    create table student(
    stuId varchar2(10),
    age number(2),
    birthday date
    )

    --添加一个字段
    alter table student add(name varchar2(10));
    --修改字段长度
    alter table student modify (name varchar2(20));

    null值:is null , is not null
    select * from student t where t.name is not null;

    savepoint 保存点的使用

    SQL> savepoint firstPoint;
    Savepoint created

    delete from student;

    rollback to firstPoint;

    drop from student;
    delete from student where age>10;
    truncate table student;--删除所有记录,表结构还在,不写日志,速度极快

    简单查询:

    列别名,函数nvl
    select t.age "年龄" ,nvl( t.age,0) "年龄为null显示0",t.rowid from STUDENT t;
    字符串连接:||
    select t.name||'-'|| t.age from student t;

    like操作符:
    %:任意0到多个字符
    _:单个任意字符 

    多列子查询:
    select * from emp where (deptNo,job)=(select deptNo,job from emp where emp='jack');

    用查询结果创建新表:
    create table mytable (id,name,sal,job,deptNo) as
    select empNo,ename,sal,job,deptNo from emp;

    union 取消重复行
    union all 不取消重复行
    intersect 取交集
    minus 取差集

    --分页查询
    select * from (select stu.*,rownum rn from (select * from student) stu where rownum <=5) where rn>=2;

  • 相关阅读:
    [考试反思]0316省选模拟47:偏颇
    [考试反思]0315省选模拟46:执念
    [考试反思]0314省选模拟45:偏离
    [考试反思]0313省选模拟44:习惯
    [考试反思]0310省选模拟42:清醒
    bd-----文本分析
    bigdata7--正则表达式
    bigdata6----vi编辑器
    bigdata4----linux文本操作命令
    bigdata4----linux文件系统命令
  • 原文地址:https://www.cnblogs.com/ICE_Inspire/p/9297406.html
Copyright © 2020-2023  润新知