1, 连接数据库;
connectscott/123456;
断开数据库
disconn;
2, 查看表结构
describescott.emp;
3, 查看数据表
selectempno,job,mgr,sal;
4,将缓冲区中的 sql 语句保存到文件
savescott_emp_query.sql
5,将文件内容读入到缓冲区中
getscott_emp_query.sql list
6,使用 start 命令读取并运行 sql 文件
startscott_emp_query.sql
7, 将缓冲区内容复制到名为 afiedt.buf 文件 (这个是默认文件) 中
edit
8,将输出结果保存到指定文件中
spoolscott_emp_outcome.txt append
9, 带变量的语句 &
selectempno,ename,mgr,sal,deptno
fromscott.emp
whereempno >=&temp;
10, 带两个变量的语句 (两次输入)
select&column_name,deptno
fromscott.emp
where&column_name>=7850;
11, 带两个变量的语句(一次输入)
select&&column_name ,deptno
fromscott.emp
where&&column_name>=7850;
12, 不显示 “原值” 和 “新值” 信息
setveryify off;(on 是显示)
新招: 反斜杠 "/" 再次运行上面的查询
13,设置变量定义字符
setdefine '@'(设置以后定义变量的字符就变为 @,& 无效)
14,执行 sql 文件的语句
@E:\TEMP\temp.sql (此处应当注意,路径是区分大小写的)
15,使用 define 查看常量
define;
16, 设置常量
definetemp=7850
查看常量
definetemp
删除常量
undefinetemp
17, 使用 column 设置输出格式
columnempno heading '员工编号' format 9999column ename heading '员工姓名' format a10columnmgr heading '上级编号' format 9999column hiredate heading '受雇日期' justfifycentercolumn sal heading '员工工资' format $999,999.99select empno,ename,mgr,hiredate,salfromscott.emp;
18, 设置一页显示多少行数据
setpagesize 20
19, 设置一行显示多少字符
setlinesize 20
20, 设置页眉页脚
ttitle页眉, btitle 页脚
21,break 命令用来分组,compute 命令用来计算和
breakon deptno;
computesum of sal on deptno;
selectempno,ename,mgr,sal,deptno
fromscott.emp order by deptno;
22, 清除 column 格式
clearcolumns
23, 创建永久性表空间
createtablespace myspace
datafile'文件路径'
size文件大小
autoextendon next 自动增加大小
maxsize文件最大值
语法说明:1,temporary|undo(创建撤销表空间)2,teblespace_name 3,datafile|tempfile'file_name'4,size5,reuse 若存在,则删掉并重新创建6,autoextendoff|on7,next number 自动扩展的大小8,maxsize unlimited|number 指定数据文件最大大小9,mininum extentnumber 盘区可以分配到的最小尺寸10,blocksize number 设置数据块大小11,online|offline 12,logging|nologging13,force logging 强制表空间数据库对象任何操作都产生日志,否定1214,default storage storage 指定保存在表空间中的数据库对象默认存储参数15,compress|nocompress是否压缩数据(消除列中的重复值)16,permanent|temporary 指定表空间中数据的保存形式17,extent managementdictionary(数据字典形式管理)|local(本地化形式管理)18,autoallocate|uniform size number 右边为指定表中盘区大小 19,segment spacemanagement auto |manual 指定表空间中段的管理方式
24,查看表空间属性
select* from dba_tablespace wheretablespace_name='表空间名';
25, 修改表空间状态
altertablespace 表空间名表空间状态;
26,修改表空间名字
altertablespace 表空间名 1 rename to 表空间名 2;
27,利用数据字典查看空闲空间信息
select* from dba_free_space where tablespace_name='表空间名称';
28, 利用数据字典查看表空间数据文件信息
select* from dba_data_files wheretablespace_name='表空间名称';
29, 修改表空间对应的数据文件大小
alterdatabase
datafile'表空间文件路径名称'
resize大小
30, 为表空间增加新的数据文件
altertablespace myspace
adddatafile '数据文件路径名称'
size大小
autoextendon next 自增大小 maxsize 最大值;
31, 删除 myspace 表空间数据文件
altertablespace myspace
dropdatafile '数据文件名称';
32,修改 myspace 表空间中数据文件的自动扩展性
alterdatabase
datafile'表空间文件路径名称'
autoextendoff;
33, 设置表空间文件状态为 offline drop
alterdatabase
datafile'表空间路径名称'
offlinedrop;
34, 移动表空间中的数据文件
(1)altertablespace 表空间名称 offline; 先设置表空间状态为 offline
(2)手动操作,将磁盘中的表空间数据文件移动到新的路径
(3)使用 alter tablespace 语句修改表空间文件路径名称
altertablespace myspace
renamedatafile '表空间路径名称'
to
'新的表空间路径名称';
(4)修改 myspace 表空间状态
altertablespace 表空间名称 online;
35, 删除表空间
droptablespace 表空间名称
includingcontents and datafiles;
36, 创建临时表空间
createtemporary tablespace 表空间名称
tempfile'表空间路径名称'
size大小
autoextendon next 自增大小 maxsize 最大大小;
37, 创建临时表空间,将所在组指定为 group1
createtemporary tablespace 表空间名称
tempfile'表空间路径名称'
size大小
tablespacegroup group1;
38, 修改临时表空间组
altertablespace 临时表空间名称 tablespace group group2;
39, 创建大文件表空间
createbigfile tabliespace mybigspace
datafile'表空间路径名称'
size大小;
40, 修改默认表空间
alterdatabase default tablespace 表空间名称;
41, 创建事物级临时表
createglobal temporary table temp_student(
)oncommit delete rows(事物级别的意思);
42, 使用事物级别临时表
select* from temp_student;
commit;提交事物。
提交后表还在,但数据被清除
43, 创建会话临时表
createglobal temporary table temp_book(
)oncommit preserve rows(会话级别的意思);
commit;
断开该用户连接才会清除数据
44,读取外部文件
首先要在对应路径下有文件
然后 create directory external_cardas'E:\external';
创建对应路径
接下来就是创建外部表
createtable e_card(
对应的数据
)organizationexternal(
//里边这一团是什么东西噢
typeoracle_loader// 指定访问外部数据文件的驱动程序,oracle 默认为 oracle_loader
defaultdirectory external_card // 对应上一步路径
accessparameters(
fieldsterminated by ',')
location('card.txt')
);
45,reject limit 句子的使用
外部表易出错,用这个就允许有无数个错误
createtable e_card(
对应的数据
)organizationexternal(
typeoracle_loader
defaultdirectory external_card
accessparameters(
fieldsterminated by ',')
location('card.txt')
)rejectlimit unlimited;
46, 将错误数据存储到指定文件
createtable e_card(
对应的数据
)organizationexternal(
typeoracle_loader
defaultdirectory external_card
accessparameters(
recordsdelimited by newline
badfile'card_bad.txt'
fieldsterminated by ',')
location('card.txt')
);
47, 错误信息日志文件
createtable e_card(
对应的数据
)organizationexternal(
typeoracle_loader
defaultdirectory external_card
accessparameters(
recordsdelimited by newline
badfile'card_bad.txt'
logfile'card_log.txt'
fieldsterminated by ',')
location('card.txt')
);
48, 创建范围分区表
createtable part_book(
数据库内容
)partitionby range(booktime)(
partitionpart1 values less than ('01-1 月 - 2008')tablespacemytemp1,
partitionpart2 values less than ('01-1 月 - 2009')tablespacemytemp2,
partitionpart1 values less than (maxvalue)tablespacemytemp3
)
49, 创建散列分区表
createtable part_book(
数据库内容
)partitionby hash(bid)(
partitionpart1 tablespace mytemp1,
partitionpart2 tablespace mytemp2,
)
50, 创建列表分区表
createtable part_book(
数据库内容
)partitionby list(bookpress)(
partitionpart1 values ('清华大学出版社') tablespace mytemp1,
partitionpart1 values ('岭南师范出版社') tablespace mytemp2
)
51,创建组合范围散列分区表
createtable part_book(
数据库内容
)partitionby range(booktime)
subpartitionby hash(bid)
subpartitions2 store in(mytemp1,mytemp2)
(
partitionpart1 values less than ('01-1 月 - 2008'),
partitionpart1 values less than ('01-1 月 - 2009'),
partitionpart1 values less than (maxvalue)
);