Oracle建表(create table)
数据类型 | 类型解释 |
VARCHAR2(length) |
字符串类型:存储可变的长度的字符串,length:是字符串的最大长度,默认不填的时候是1,最大长度不超过4000。 |
CHAR(length) |
字符串类型:存储固定长度的字符串,length:字符串的固定长度大小,默认是1,最大长度不超过2000。 |
NUMBER(a,b) |
数值类型:存储数值类型,可以存整数,也可以存浮点型。a代表数值的最大位数:包含小数位和小数点,b代表小数的位数。 number(6,2),输入123.12345,实际存入:123.12 。 number(4,2),输入12312.345,实际春如:提示不能存入,超过存储的指定的精度。 |
DATA |
时间类型:存储的是日期和时间,包括年、月、日、时、分、秒。例子: 内置函数sysdate获取的就是DATA类型 |
TIMESTAMP |
时间类型:存储的不仅是日期和时间,还包含了时区。例子: 内置函数systimestamp获取的就是timestamp类型 |
CLOB |
大字段类型:存储的是大的文本,比如:非结构化的txt文本,字段大于4000长度的字符串。 |
BLOB |
二进制类型:存储的是二进制对象,比如图片、视频、声音等转换过来的二进制对象 |
创建stuinfo(学生信息表)
-- Create table
create table STUDENT.stuinfo
(
stuid varchar2(11) not null,--学号:'S'+班号(7位数)+学生序号(3位数)(1)
stuname varchar2(50) not null,--学生姓名
sex char(1) not null,--性别
age number(2) not null,--年龄
classno varchar2(7) not null,--班号:'C'+年级(4位数)+班级序号(2位数)
stuaddress varchar2(100) default '地址未录入',--地址 (2)
grade char(4) not null,--年级
enroldate date,--入学时间
idnumber varchar2(18) default '身份证未采集' not null--身份证
)
tablespace USERS --(3)
storage
(
initial 64K
minextents 1
maxextents unlimited
);
-- Add comments to the table
comment on table STUDENT.stuinfo --(4)
is '学生信息表';
-- Add comments to the columns
comment on column STUDENT.stuinfo.stuid -- (5)
is '学号';
comment on column STUDENT.stuinfo.stuname
is '学生姓名';
comment on column STUDENT.stuinfo.sex
is '学生性别';
comment on column STUDENT.stuinfo.age
is '学生年龄';
comment on column STUDENT.stuinfo.classno
is '学生班级号';
comment on column STUDENT.stuinfo.stuaddress
is '学生住址';
comment on column STUDENT.stuinfo.grade
is '年级';
comment on column STUDENT.stuinfo.enroldate
is '入学时间';
comment on column STUDENT.stuinfo.idnumber
is '身份证号';
stuinfo(学生信息表)添加约束
--