oracle字段介绍

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自学教程 --create tabletestone ( id number, --序号usernam...
    落叶寂聊阅读 1,161评论 0 0
  • (一)Oracle数据库 1.oracle中row_id理解 ORACLE的row_id是一个伪列,其个是为18个...
    独云阅读 5,697评论 0 10
  • 广州的夏天是一种让人窒息的热,校园内外都是一片死寂。 就只有校门口对面冰室里的人群,添上了一丝不协...
    萧风_暖语阅读 1,150评论 0 0
  • 秀里坝下百年枫, 枝繁叶茂傲苍穹。 若待来年秋风起, 一树丹花映日红。
    迹远留香阅读 215评论 0 1
  • 河对岸的那朵花 在风中轻轻摇曵 舒展的枝叶,鲜艳的花朵 美成一幅画 蝴蝶飞来了 蜜蜂也来了 她们一起舞蹈 然后玩起...
    冬之花阅读 186评论 1 2