oracle数据库表的创建,修改以及表内数据的增删改查
一、DDL表的创建,表的修改
#创建表t1
create table t1(
id number,
name varchar2(20) default'无名氏',
sex varchar2(10) default'男',
age number(3)
)
#查看表是否创建成功
select * from t1
desc t1;
#添加列
alter table tb1 add score NUMBER(4,2);
#修改某字段的数据类型
alter table t1 modify score varchar2(10);
#修改字段名
alter table t1 rename column score to aa;
#修改表名
rename t1 to tb1;
#删除列
alter table tb1 drop column aa;
二、DML增删改查
#数据更新操作
create table tb2 as select * from tb1
2.1#向表中添加数据
insert into t1(id,name,sex,age) values(1,'张无忌','男',18)
insert into t1(id,name,sex,age) values(2,'赵敏','女',17)
insert into t1(id,name,sex,age) values(3,'周芷若','女',18)
2.2#一次性插入多条数据
具体应该使用如下的方式批量插入数据。
INSERT ALL
INTO t1(id,name,sex,age) VALUES (4,'杨逍','男',40)
INTO t1(id,name,sex,age) VALUES (5,'灭绝师太','女',46)
INTO t1(id,name,sex,age) VALUES (6,'金毛狮王','男',50)
SELECT * FROM tb1;
2.3#数据修改---将张无忌的年龄修改为19
update tb2 set age=19 where name='张无忌'
2.4数据删除---将周芷若行删除
delete from tb2 where name='周芷若'
2.5删除所有数据
DELETE FROM tb2 ;