oracle数据库操作

根据慕课网课程Oracle数据库开发必备利器之SQL基础 整理

一。基本

(1).系统用户

  • sys,system 密码在安装时设置
  • sysman操作企业管理系统 密码在安装时设置
  • scott初始密码是tiger

(2).登录

 username/password @server(例如@orcl 可省略) 【as sysdba】

若已经登录再登录 需要前面加connect

(3)查看当前用户

show user

(4).常用数据字典

  • dba_users
  • user_users
  • dba_tablespaces
  • user_tablespaces

(5).查看表或表空间结构

  desc sth

二。表空间

(1)表空间分类

  • 永久性
  • 临时性(中间执行过程中。。。。)
  • UNDO(事务修改数据的旧值)

(2) 更改用户的表空间

alter user scott default/temprorary tablespace sth

(3)创建临时表空间

create temporary tablespace teblespace_name TEMPFILE 'xx.dbf' size xx

(4)创建默认表空间

create tablespace teblespace_name DATAFILE 'xx.dbf' size xx(m,k,g)

xx.dbf 可以为绝对路径 相对路径

(5)修改表空间状态

alter tablespace tablespace_name online/offline/read only/read write

只有在online时才有只读和读写这么一说

(6)查看表空间状态

select status from dba_tablespaces/user_tablespaces
where tablespace_name= ' '

(7)删除表空间

      drop tablespace tablespace_name  [including contents]

(8)增删数据文件

alter tablespace tablespace_name
add datafile 'xx.dbf' size xx

alter tablespace tablespace_name
drop datafile 'xx.dbf'

三。管理表

(1)数据类型

  1. char(n) nchar(n)(支持中文) 不变长度
  2. varchar2(n) nvarchar2(n) 可变长度
  3. number(p, s) 有效数字,小数点后几位
  4. float(n) 存二进制数据 (一般不用)
  5. date 常用
  6. timestamp更精确
  7. blob二进制
  8. clob字符串

(2)创建表

create table userinfo
( id number(6,0),
username varcher2(20),
userpwd varchar2(20),
email varchar(30),
redate date );

(3)添加字段

alter table table_name
add columu_name datatype;

(4)更改字段数据类型

alter table table_name
modify columu_name datatype;

(5)删除字段

alter table teble_name
drop columu columu_name;

(6)修改字段名

alter table table_name
rename columu columu_name to new_columu_name;

(7)修改表名

rename table_name to new_table_name

(8)删除表

truncate table table_name; 只清空表中的数据
drop table table_name;      删除表结构

四。操作表中的数据

(1)插入

insert into table_name values(..)
create table_new as select ......
insert into table_new select ....

(2)删除

delete from table_name
where ...

(3)修改

update table_name 
set columu1=value1...
where ...

你可能感兴趣的:(oracle数据库操作)