创建索引:

自动

– 创建 PRIMARY KEY

– 创建 UNIQUE KEY


手动

– CREATE INDEX 语句

– CREATE TABLE 语句


create table  语句中 create index


 create table new_emp (employee_id number(6) primary key using index

(create index emp_id_idx on

new_emp(employee_id)),

first_name varchar2(20),

last_name varchar2(25));


select index_name, table_name from user_indexes  where table_name = 'new_emp';


基于函数的索引

  • 基于函数的索引就是一个基于表达式的索引

  • 索引表达式由列、常量、SQL 函数和用户自定义函数构成的


create index upper_dept_name_idx on dept2(upper(department_name));


select * from dept2 where upper(department_name) = 'SALES';


删除索引

使用 DROP INDEX 命令从数据字典中删除索引:

drop index index;

从数据字典中删除 UPPER_DEPT_NAME_IDX 索引:

drop index upper_dept_name_idx;

删除索引,您必须是索引的拥有者或者有 DROP ANY INDEX权限


drop table dept80 purge;


FLASHBACK TABLE  语句

  • 一条语句就可以恢复到指定时间点。

  • 恢复表中的数据以及相关的索引和约束。

  • 可以根据某一时间点或者系统改变号(SCN) 来恢复表。


表意外修改的修复工具:

– 表恢复到一个较早的时间点

– 优点:易用性、可用性、快速执行

– 执行到位(Is performed in place)


语法:

flashback table[schema.]table[,

[ schema.]table ]...

to { timestamp | scn } expr

[ { enable | disable } triggers ];


示例:

drop table emp2;

select original_name, operation, droptime from recyclebin;

flashback table emp2 to before drop;


临时表

创建临时表

create global temporary table cart on commit delete rows;


create global temporary table today_sales

on commit preserve rows as

select * from orders

where order_date = sysdate;


外部表

为外部表创建目录

创建 DIRECTORY对象,对应外部数据源所在的文件系统上的目录。

create or replace directory emp_diras '/.../emp_dir';

grant read on directory emp_dir to ora_21;


创建外部表

create table <table_name>

( <col_name> <datatype>, ... )

organization external

(type <access_driver_type>

default directory <directory_name>

access parameters

(...) )

location ('<location_specifier>')

reject limit [0 | <number> | unlimited];


使用ORACLE_LOADER 驱动创建外部表

create table oldemp (

fname char(25), lname char(25))

organization external

(type oracle_loader

default directory emp_dir

access parameters

(records delimited by newline

nobadfile

nologfile

fields terminated by ','

(fname position ( 1:20) char,

lname position (22:41) char))

location ('emp.dat'))

parallel 5

reject limit 200;


查询外部表

select * from oldemp

使用ORACLE_DATAPUMP驱动创建外部表:

create table emp_ext

(employee_id, first_name, last_name)

organization external

(

type oracle_datapump

default directory emp_dir

location

('emp1.exp','emp2.exp')

)

parallel

as

select employee_id, first_name, last_name

from employees;