oracle 实例

第一部分:基础部分

 

表空间、用户及授权

//创建表空间
SQL> create tablespace lh_space datafile 'f:\oracle\product\10.2.0\udb\lhspace.d
bf' size 100m autoextend on next 3m maxsize unlimited;

//删除表空间
SQL> drop tablespace lh_space including contents and datafiles;


//创建用户
SQL> create user lh identified by lh2011 default tablespace lh_space;

//为用户授权
SQL> grant connect,resource to lh;--连接,资源授权
SQL> grant create database link to lh;--数据库连接权限

表、索引、序列及字段

//创建表
SQL> create table sys_user
  2  ( id number primary key,
  3  name varchar2(50),
  4  birth date);

//创建索引
SQL> create unique index id_sys_user_name on sys_user (name) tablespace lh_space
;--唯一索引


//查看添加的索引
SQL> select index_name,index_type,table_name from user_indexes;


//创建序列
SQL> create sequence sq_sys_user_id  minvalue 10 start with 10 increment by 1 no
cache;

//使用序列

SQL> select sq_sys_user_id.nextval from dual;

   NEXTVAL
----------
        10

SQL> select sq_sys_user_id.currval from dual;

   CURRVAL
----------
        10

SQL> insert into sys_user values(sq_sys_user_id.nextval,'张飞',to_date('1986-10-
10','yyyy-mm-dd'));



//修改字段类型
SQL> alter table sys_user modify name varchar2(10);


//如果字段有已有数据,可这样处理
alter table tb_test add permile_temp number(5,2) —1.添加一个新字段
update tb_test set  permile_temp=permile;        --2.将旧字段的值赋给新字段
alter table drop column permile;                 --3.删除旧字段
alter  table test rename column  permile_temp to permile;--更改新字段名称


//查询-锁定模式(LockMode)
Select * from sys_user where id=1 for update;

第二部分:数据库导入导出

 

导出

导出dmp格式备份文件

 

C:\Documents and Settings\Administrator>exp

Export: Release 10.2.0.1.0 - Production on 星期二 10月 4 11:04:48 2011

Copyright (c) 1982, 2005, Oracle.  All rights reserved.

用户名: lh
口令:

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Productio
With the Partitioning, OLAP and Data Mining options
输入数组提取缓冲区大小: 4096 >

 导出文件: EXPDAT.DMP > d:\lhspace111004.dmp

(2)U(用户), 或 (3)T(表): (2)U >

导出权限 (yes/no): yes >

导出表数据 (yes/no): yes >

压缩区 (yes/no): yes >

已导出 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集
……

 

 

//导入dmp

 

C:\Documents and Settings\Administrator>imp
Import: Release 10.2.0.1.0 - Production on 星期二 10月 4 11:19:12 2011
Copyright (c) 1982, 2005, Oracle.  All rights reserved.

用户名: lh
口令:

连接到: Oracle Database 10g Enterprise Edition Release 10.2.0.1.0 - Production
With the Partitioning, OLAP and Data Mining options

导入文件: EXPDAT.DMP> d:\lhspace111004.dmp

输入插入缓冲区大小 (最小为 8192) 30720>

经由常规路径由 EXPORT:V10.02.01 创建的导出文件
已经完成 ZHS16GBK 字符集和 AL16UTF16 NCHAR 字符集中的导入
只列出导入文件的内容 (yes/no): no >

由于对象已存在, 忽略创建错误 (yes/no): no > yes

导入权限 (yes/no): yes >

导入表数据 (yes/no): yes >

导入整个导出文件 (yes/no): no > yes

. 正在将 LH 的对象导入到 LH
. . 正在导入表                      "SYS_USER"导入了           3 行
……
 

猜你喜欢

转载自hbxflihua.iteye.com/blog/1477858