数据类型
- number:没有指定长度限制
- varchar2(100):字符串类型,oracle特有的,最大长度4000,可变长度,把空字符串当作null处理。
- varchar(100) : 字符串类型,sql标准,可以存储空字符串,oracle 建议使用varchar2 。
- char(100) : 字符串类型,定长,例如存储字符串 ’ABC’, char(100) 使用100个字节,97个字节是空的,而varchar2 (100) 只使用3个字节,100只是指定了最大长度。
- date:日期类型,sysdate 表示系统日期,默认格式15-04-21表示2021.4.15
- long: 存储的是可变长字符串,最大长度限制是2GB。long: 存储的是可变长字符串,最大长度限制是2GB。
- blob: 二进制大型对象(Binary Large Object), 最大为4G, 用来存储图片,文件,音乐等。
- clob:字符大型对象(Character Large Object), 存储长的文本,最大为4G。
新建用户TEST,并赋予权限Resource和connect参考,并用test用户进行下列操作管理员用户建的表,不能删除
创建表
create table 表名
(
stname varchar2(10) not null ,
stsex char(3),
stid char(4)
stgrade varchar(5) default '一年级'
);
create table table01
(
stname varchar2(10) not null,
stsex char(3),
stid char(4),
stgrade varchar(6) default '一年级'
);
查询表
select * from user_table;
select * from user_tab_cols where table_name = '大写用户名'
select * from user_tab_cols where table_name = 'TABLE01'
修改
alter table table01 rename to test01
select * from 表格名 for update;
select * from table01 for update;
create table 新表格名 as select * from 被复制的表格名;
create table table02 as select * from table01;
create table table04 as select * from table01 where stname = 'a';
create table 表2 as select 字段2,字段1 from 表1;
create table table03 as select stname,stid,table01 from name,id;
insert into table05(stname,stsex)select stname,stsex from table01;
alter table table01 add (stwy number(11));
alter table table01 rename column stwy to st_class;
alter table table01 modify(stsex char(4),2);
insert into 表名 values(列1的值,列2的值,...有多少列写多少值);
insert into table01 values('a1','男',14,'二年级')
update 表名 set 列名=新的值 where 条件;
update table01 set stid=13 where sname = 'a1'
查看
select * from user_tab_colums where table_name='TABLE01';
comment on table 表名 is '学生信息表';
comment on column 表名.字段名 is '学生编号';
删除
alter table table01 add(sttel char(13));
alter table table01 drop column sttel;
delete from table03 where stname = 'a1';
truncate table table05;
drop table table05;