一、基本语句
sqlplus /nolog
conn username/pwd
col colname from 9999/a23
run 显示sql指令,/不显示,都是可以在缓冲区获得上一次输入的命令结果
附加a 加上任意命令
list查看缓冲区的数据
del不输入数字,删除默认最后一行
ch /被替换指令/替换指令
set line
select table_name from user_tables/all_tables
save d:\1.sql保存脚本文件
@d:\1.sql执行脚本文件
edit d:\1.sql修改脚本文件
get d:\1.sql得到脚本文件
二、数据库体系结构
一个实例是由一个SGA和后台进程组成
一个实例对应一个数据库,一个数据库对应多个实例
oracle数据库物理结构:数据文件、控制文件、重做日志文件
三、创建数据库
dbca,
create datebase
安装软件时创建数据库
四、SQL字符型单行函数
lower(column\expression),upper,initcap,concat,substr,replace,
round,trunc,mod,sysdate,months between,add_months,next_day,last_day
select sysdate+7,sysdate-7 from dual;
五、数据类型
nvarchar,nchar,date,number(38,124),rowid,
创建表
create table hxy.temp_employee(
employee_id number(6),
employee_name nvarchar(30)
)
创建临时表
create global temporary table
hxy.emp_temp
on commit preserve rows
as
select * from hxy.emp
alter table hxy.employee
add(name varchar2(10));
alter table hxy.employee
modify(degree varchar(2) not null);
drop table彻底删除表中的数据和结构
truncate只删除表中的数据
drop column
六、条件表达式
case expr
when then
when then
else
end
decode (col,search1,result1,...,sal)
七、sql结构话查询语言
八、空值
is null
nvl nvl2
coalesce
九、分组
avg sum max min count,group by,having
select job,avg(sal) from emp having abg(sal)>2000
group by job;
十、简单查询
连接查询||'is a'||job
十一、创建视图
create view name_view
()as
select ...
with read only/with check potion
=----------------
事务
commit rollback
-----------------
数据字典
静态数据字典dba_,all_,user_
动态数据字典v$
connect system/oracle as sysdba
select name,created rom v$database
select host_name,instance_name,version from $instance
select status,name from v$controlfile
select group#,members,status,archived from v$log;
归档模式
archived log list
select file_id,file_name,tablespace_name from dba_data_files;
---------------------------
连接查询
乘积连接
自然连接m+n-r
自连接
外连接(+)=
-----------------------------
索引
col index_name for a20
create index index_name on employee(name);
create index name on employee(ename,sal) tablespace index_tbs;
create tablespace index_tbs
datafile '.dbf'
size 100m
autoextend on;
使用数据字典查看索引
user_indexes
B树索引:根节点、分支节点、叶子节点
位图索引:没有大部分更新的数据仓库bitmap index
反向索引
create index name
on emp(sal) reverse;
基予函数的索引
create index name
on emp(upper(name));
本地分区索引
create index name on products(date) local
tablespace product_tbs;
监控索引使用
alter index name
monitoring usage;
v$object_usage
重建索引
alter index name
rebuild
(tablespace index_tbs);
索引维护
select index_name,pct_free,pct_increase,initial_extent,next_indexes
pctfree增加表空间
storage(next 1ook)
allocate extent手动增加索引磁盘空间
coalesce合并索引
drop index name
-------------------
启动oracle数据库
nomount打开数据库实例
mount找到打开控制文件,并读取,不打开数据文件
open打开数据文件,进行检查
startup nomount;
alter database mount/open;
show parameter controlfile;
select * from v$controlfile;
关闭数据库
shutdown immediate;比较安全的一种方式
shutdown transactional等待事务进行完在关闭,不允许新的连接
shutdown abort 立即断开所有连接
shotdown normal默认方式,不允许新的连接,当前所有连接退出,安全的,有大量数据连接需要时间
http://edu.51cto.com/lession/id-2863.html