`
hbxflihua
  • 浏览: 660707 次
  • 性别: Icon_minigender_1
  • 来自: 杭州
社区版块
存档分类
最新评论

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 行
……
 

 

 

 

 

 

分享到:
评论
4 楼 hbxflihua 2012-11-05  
left join的困惑:一旦加上where条件,则显示的结果等于inner join
left join后用where 是先连接然后再筛选  
left join后用and 是先筛选再连接
3 楼 hbxflihua 2012-10-31  
启动Oracle监听服务命令:
lsnrctl start


启动oracle服务命令:
sqlplus system/123456 as sysdba
shutdown immediate
startup


---查询一张表的表信息
select table_name,--表名
tablespace_name,--所在表空间
temporary  --临时表空间
from user_tables 
where table_name='SCIENPROJECT'--表名


---查询一个表中的列属性
select column_name,--列名
data_type ,--列类型
data_length,--列长度
data_precision,--列精度
data_scale --范围
from user_tab_columns 
where table_name='SCIENPROJECT'--表名


Oracle中使用WMSYS.WM_CONCAT函数进行多行转列
2 楼 hbxflihua 2012-10-27  
导出远程服务器上的数据库
exp user/password@alias_remote_orcl file=d:\orcl_20121027.dmp

这里 user是具有数据库管理权限的用户名
password 是该用户的登录密码
alias_remote_orcl 是远程数据库别名
1 楼 hbxflihua 2012-10-12  
oracle 远程连接配置
前提条件,本地oracle数据库安装无误,sql plus可连接数据库进行相关操作。然后打开tnsnames.ora文件,该文件目录${oracle}\product\10.2.0\db_1\NETWORK\ADMIN。默认情况下,该文件会被空行隔成三块,头部分是注释,下面是TNS连接配置。在下面两块直接添加如下代码:
alias_remote_orcl =
  (DESCRIPTION =
    (ADDRESS_LIST =
      (ADDRESS = (PROTOCOL = TCP)(HOST = remote_ip)(PORT = 1521))
    )
    (CONNECT_DATA =
      (SERVICE_NAME = remote_orcl)
    )
  )


其中,alias_remote_orcl 是远程数据库别名。
remote_ip 是远程数据库所在的IP地址。
remote_orcl 是远程数据库名称。
还有就是端口,有些数据库可能端口也有变化。我在配置后,总是出现无法连接的异常。后来仔细看了看,原来是远程数据库别名的问题,记得别名一定要顶格写,与后面的等号可以间隔一定的距离。

相关推荐

Global site tag (gtag.js) - Google Analytics