美文网首页
oracle字段介绍

oracle字段介绍

作者: 未小琴 | 来源:发表于2018-10-29 17:33 被阅读9次

    1、char
    存储固定长度字符串 最大长度为2000 如果没有说明,默认长度为1 如果赋值长度小于规定的固定长度,oracle自动用空格填充。
    2、varchar2
    存储可变长度的字符串,最大长度4000 不需要用空格
    3、date

    4、oracle 简单操作语句
    create table student_tab( --创建学生信息表
    stuid varchar2(20) primary key,
    stuname varchar2(100) not null,
    stusex varchar2(20) not null,
    classnum varchar2(50) not null,
    stuaddress varchar2(200) default '地址未录入',
    age number(20) not null,
    grade varchar2(100) not null,
    idnumber varchar2(100) not null
    );

    create table student_lesson( --创建课程表
    lessid varchar2(11) primary key,
    lessname varchar2(30) not null
    );
    create table student_score( --创建成绩表
    scoid varchar2(2000) primary key,
    stuid varchar2(2000) references student_tab(stuid) not null , --外键
    lessscore varchar2(2000) not null
    );
    -- 简单查表
    select * from student_tab;
    select * from student_lesson;
    select * from student_score;

    --增加多个字段
    alter table student_score add (A21 number(10) null,A22 varchar2(20) null,A23 varchar2(20) null);

    --删除多个字段
    alter table student_score drop(A21,A22,A23);

    --删除表
    drop table student_tab;
    drop table student_score;

    --插入数据
    insert into student_tab values('001','小明','女','002','甘肃省',8,'8','123456789');
    insert into student_tab values('002','农夫山','男','003','四川省',5,'7','2485937');
    insert into student_tab values('003','未央','女','092','甘肃省',78,'9','1345789');
    insert into student_tab values('054','未花','女','012','上海市',55,'5','6789');
    insert into student_tab values('285','树儿','女','102','北京市',33,'6','16789');

    insert into student_lesson values('002','数据结构与算法');
    insert into student_lesson values('003','操作系统');
    insert into student_lesson values('022','数据库');
    insert into student_lesson values('402','J2EE');
    insert into student_lesson values('102','计算机体系结构');

    insert into student_score values('001','001','98');
    insert into student_score values('003','004','88');
    insert into student_score values('051','003','100');
    insert into student_score values('401','002','95');

    --更新数据(插入某一字段值)
    update student_tab set stubirthday=to_date('2012-01-05','yyyy-mm-dd') where stuid='001';

    --更新数据
    update student_tab set stuname='小小' where stuname='未央';

    --删除数据
    delete from student_tab where stuname='小小';

    --修改表名
    alter table student_tab rename to student_info;
    alter table student_tab rename to student_tab;

    --复制表内容
    create table new_student_lesson(
    );
    insert into new_student_lesson (select * from student_lesson);

    --简单两表连接查询
    select a.stuid,a.stuname,a.stusex,b.lessscore from student_tab a,student_score b where a.stuid=b.stuid;
    select a.stuid,a.stuname,b.lessname,s.lessscore from student_tab a,student_lesson b,student_score s where
    a.stuid=s.stuid and(a.stuname='未%'or stusex='女');

    --查询结果消除重复行
    select distinct a.stuid,a.stuname,b.lessname,s.lessscore from student_tab a,student_lesson b,student_score s where
    a.stuid=s.stuid and(a.stuname='未%'or stusex='女');

    --升序order by asc(默认) 降序order by desc
    select * from student_score ls order by stuid DESC;
    select * from student_score ls order by stuid ; --默认升序

    --模糊查询
    select stuname from student_tab where stuname like '%央';

    --给表增加字段
    alter table student_tab add (stubirthday date);

    --修改字段类型
    alter table student_tab modify(stusex char(200));

    相关文章

      网友评论

          本文标题:oracle字段介绍

          本文链接:https://www.haomeiwen.com/subject/pjgbtqtx.html