暂无图片
暂无图片
暂无图片
暂无图片
暂无图片

Oracle 常用必备 SQL

Oracle优化大师 2017-11-06
738

     随着Oracle数据库的成熟和发展, 数据库开发工具越来越多,比如 Toad ,PL/SQL Dev 等,使用其他非 oracle 自带工具,意味着二次资源消耗。

     还是‘原汁原味’好。

     因此 必要的基础‘武功’ 最重要; 救命的SQL*Plus 最好用了。


1, 清除 column 格式

clear  columns


2, 创建永久性表空间

create tablespace myspace 

datafile '文件路径'

size 文件大小

autoextend on next 自动增加大小

maxsize 文件最大值


语法说明:
1>,temporary|undo(创建撤销表空间)
2>,teblespace_name 
3>,datafile|tempfile'file_name'
4>,size
5>,reuse 若存在,则删掉并重新创建
6>,autoextend off|on
7>, next number 自动扩展的大小
8>,maxsize unlimited|number 指定数据文件最大大小
9>,mininum extent number 盘区可以分配到的最小尺寸
10>,blocksize number 设置数据块大小
11>,online|offline 
12>,logging|nologging
13>,force logging 强制表空间数据库对象任何操作都产生日志,否定 12
14,default storage storage 指定保存在表空间中的数据库对象默认存储参数
15>,compress|nocompress 是否压缩数据(消除列中的重复值)
16>,permanent|temporary 指定表空间中数据的保存形式
17>,extent management dictionary(数据字典形式管理)|local(本地化形式管理)
18>,autoallocate|uniform size number 右边为指定表中盘区大小 
19>,segment space management auto |manual 指定表空间中段的管理方式

3,查看表空间属性

SELECT *

  FROM  dba_tablespace wheretablespace_name = '表空间名';



4, 修改表空间状态

alter tablespace 表空间名 表空间状态;


5,修改表空间名字

alter tablespace 表空间名 1 rename to 表空间名 2;


6,利用数据字典查看空闲空间信息

SELECT *

  FROM dba_free_space

 WHERE tablespace_name = '表空间名称';



7, 利用数据字典查看表空间数据文件信息

SELECT *

  FROM dba_data_files wheretablespace_name = '表空间名称';



8, 修改表空间对应的数据文件大小

alter database

datafile '表空间文件路径名称'

resize 大小



9, 删除 myspace 表空间数据文件

alter tablespace myspace

drop datafile '数据文件名称';


10,修改 myspace 表空间中数据文件的自动扩展性

alter database

datafile '表空间文件路径名称'

autoextend off;


11, 设置表空间文件状态为 offline drop

alter database

datafile '表空间路径名称'

offline drop;


12, 移动表空间中的数据文件

(1)alter tablespace 表空间名称 offline; 先设置表空间状态为 offline

(2) 手动操作,将磁盘中的表空间数据文件移动到新的路径

(3) 使用 alter tablespace 语句修改表空间文件路径名称

alter tablespace myspace 

rename datafile '表空间路径名称'

to

'新的表空间路径名称';

(4) 修改 myspace 表空间状态

alter tablespace 表空间名称 online;


13, 删除表空间

drop tablespace 表空间名称

including contents and datafiles;


14, 创建临时表空间

create temporary tablespace 表空间名称

tempfile '表空间路径名称'

size 大小

autoextend on next 自增大小 maxsize 最大大小;


15, 创建临时表空间,将所在组指定为 group1

create temporary tablespace 表空间名称

tempfile '表空间路径名称'

size 大小

tablespace group group1;


16, 修改临时表空间组

alter tablespace 临时表空间名称 tablespace group group2;


17, 创建大文件表空间

create bigfile tabliespace mybigspace

datafile '表空间路径名称'

size 大小;


18, 修改默认表空间

alter database default tablespace 表空间名称;


19, 创建事物级临时表

create global temporary table temp_student(

)on commit delete rows(事物级别的意思);


20, 使用事物级别临时表

select * from temp_student;

commit; 提交事物。

提交后表还在,但数据被清除


21, 创建会话临时表

create global temporary table temp_book(

)on commit preserve rows(会话级别的意思);

commit;

断开该用户连接才会清除数据


22,读取外部文件

首先要在对应路径下有文件

然后  create directory external_card as'E:\external';

创建对应路径


接下来就是创建外部表


create table e_card(

对应的数据

)organization external(

// 里边这一团是什么东西噢

type oracle_loader// 指定访问外部数据文件的驱动程序,oracle 默认为 oracle_loader

default directory external_card 对应上一步路径


access parameters(

fields terminated by ',')

location ('card.txt')

);


23,reject limit 句子的使用

外部表易出错,用这个就允许有无数个错误

create table e_card(

对应的数据

)organization external(

type oracle_loader

default directory external_card

access parameters(

fields terminated by ',')

location ('card.txt')

)reject limit unlimited;


24, 将错误数据存储到指定文件

create table e_card(


对应的数据

)organization external(

type oracle_loader

default directory external_card

access parameters(


records delimited by newline

badfile 'card_bad.txt'


fields terminated by ',')

location ('card.txt')

);


25, 错误信息日志文件

create table e_card(

对应的数据

)organization external(

type oracle_loader

default directory external_card

access parameters(


records delimited by newline

badfile 'card_bad.txt'

logfile 'card_log.txt'


fields terminated by ',')

location ('card.txt')

);


26, 创建范围分区表

create table part_book(

数据库内容

)partition by range(booktime)(

partition part1 values less than ('01-1 月 - 2008')tablespacemytemp1,

partition part2 values less than ('01-1 月 - 2009')tablespacemytemp2,

partition part1 values less than (maxvalue)tablespacemytemp3

)


27, 创建散列分区表

create table part_book(

数据库内容

)partition by hash(bid)(

partition part1 tablespace mytemp1,

partition part2 tablespace mytemp2,

)


未完待续

http://www.7daysgps.com/


 


本文分享自微信公众号 - Oracle优化大师,如有侵权,请联系 service001@enmotech.com 删除。
最后修改时间:2019-12-20 10:51:44
文章转载自Oracle优化大师,如果涉嫌侵权,请发送邮件至:contact@modb.pro进行举报,并提供相关证据,一经查实,墨天轮将立刻删除相关内容。

评论