1.建表:
1)常规建表:
create table temp_1(
Tempcode varchar2(30) not null,
TempName varchar2(15)
);
创建字段为TempCode,TempName的temp_1表,新创建的表中无数据,如下图所示:
2)根据查询结果建表:
create table temp_1 as select tempcode,tempname from temp_2;
创建字段为TempCode,TempName的temp_1表,新创建的表中存在temp_2的存储结果,如下图所示:
3)创建事务级临时表:
create global temporary table temp_1(
Tempcode varchar2(30) not null,
TempName varchar2(15)
)
on commit delete rows
创建字段为TempCode,TempName的temp_1表,新创建的表为事务级临时表,当该表事务进行提交commit/回滚rollback时,清除表内所有数据(truncate)
4)创建会话级临时表:
create global temporary table temp_1(
Tempcode varchar2(30) not null,
TempName varchar2(15)
)
on commit preserve rows
创建字段为TempCode,TempName的temp_1表,新创建的表为会话级临时表,当会话结束时,清除表内所有数据(truncate)
2.新增
1)单行插入
insert into temp_1(tempcode) values('1001'); --指定字段插入
insert into temp_1 values('1001','张三同学'); --全字段插入
执行insert操作,如下图所示:
2)根据查询结果插入
insert into temp_1(tempcode) select tempcode from temp_2; --指定字段插入
insert into temp_1 select tempcode,tempname from temp_2; --全字段插入
指定字段插入,如下图所示:
全字段插入,如下图所示:
3.删除
1)delete:删除表数据,不删除表结构,事务提交后删除,DML语句,不释放表空间,激活触发器