SQL 基础之索引、闪回、临时表(十八)
admin
2023-05-26 15:01:11
0

创建索引:

自动

– 创建 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

( , ... )

organization external

(type

default directory

access parameters

(...) )

location ('')

reject limit [0 | | 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;

相关内容

热门资讯

布林肯又提“实力”但承认:一对... 【文/观察者网 熊超然】据央视新闻报道,5月15日下午,美国总统特朗普结束对中国的国事访问,乘专机离...
三星电子劳资谈判结束,工会决定... △三星电子(资料图)当地时间20日深夜,当天下午再度重启的三星电子劳资谈判结束。三星电子工会一方表示...
敦促乌克兰给白俄“松绑”,美国... 【文/观察者网 张菁娟】钾肥作为提升农作物产量的关键土壤养分,不仅关乎全球粮食安全,更成为当前大国地...
“AI+金融”的下一站:新场景... 记者 胡艳明 “人工智能落到金融领域,在经历过一段时间的探索之后,未来有哪些重点的方向?”2026年...
阿里发布新一代千问旗舰模型Qw... 撰稿 | 150 克 大模型进入高速迭代的第三年,行业关注的重点正在发生变化。 过去,外界衡量一家...
消息称DeepSeek组建Ha... IT之家 5 月 20 日消息,今天下午,“甲子光年”援引 DeepSeek 相关知情人士消息称,D...
机智局 | 京东将举行首场仿真... 深圳商报·读创客户端首席记者 袁静娴 近日,京东宣布,京东零售今年将助推机器人品牌累计销售破100亿...
2026年618大促,摄影性能... 618大促即将到来,不少朋友都想趁着优惠换一台新。如果你预算在一万左右,又特别看重拍照效果,那么兼具...
原创 罗... 导读:罗峰随混沌城主踏入宇宙海倾峰界外域人族基地时,有五位宇宙之主设宴相迎,他们是彭工之主、幽侯之主...