Chinaunix首页 | 论坛 | 博客
  • 博客访问: 412382
  • 博文数量: 148
  • 博客积分: 3191
  • 博客等级: 中校
  • 技术积分: 1232
  • 用 户 组: 普通用户
  • 注册时间: 2011-08-11 15:25
文章分类

全部博文(148)

文章存档

2011年(148)

我的朋友

分类: Oracle

2011-08-19 10:39:10

1、表迁移

2、查询oracle表的信息(表,字段,约束,索引)、

3、查找重复记录.

4、将查询结果存为文件

5、如何定位SESSIOIN

6、如何减少TEMP表空间

7、缩小UNDO表空间

8、帐户名与安全标识间无任何映射完成(windows)

9、ORACLE查IP地址

 

 

1、表迁移

select 'alter table budget.'|| table_name || ' move tablespace budget;' from dba_tables where owner='BUDGET'

select 'alter index budget.'||index_name||' REBUILD   TABLESPACE budget;' from dba_indexes where owner='BUDGET'

 

2、查询oracle表的信息(表,字段,约束,索引)

查询oracle表的信息(表,字段,约束,索引)

1、查询出所有的用户表

select   *   from   user_tables   可以查询出所有的用户表

2、查询出用户所有表的索引

select   *   from   user_indexes

3、查询用户表的索引(非聚集索引):

select   *   from   user_indexes where   uniqueness='NONUNIQUE'

4、查询用户表的主键(聚集索引):

select   *   from   user_indexes where   uniqueness='UNIQUE'

5、查询表的索引

select t.*,i.index_type from user_ind_columns t,user_indexes i where t.index_name = i.index_name and

t.table_name='NODE'

6、查询表的主键

select cu.* from user_cons_columns cu, user_constraints au where cu.constraint_name = au.constraint_name and

au.constraint_type = 'P' AND cu.table_name = 'NODE'

7、查找表的唯一性约束(包括名称,构成列):

select column_name from user_cons_columns cu, user_constraints au where cu.constraint_name=au.constraint_name and

cu.table_name='NODE'

8、查找表的外键

select * from user_constraints c where c.constraint_type = 'R' and c.table_name='STAFFPOSITION'

查询外键约束的列名:

select * from user_cons_columns cl where cl.constraint_name = 外键名称

查询引用表的键的列名:

select * from user_cons_columns cl where cl.constraint_name = 外键引用表的键名

9、查询表的所有列及其属性

select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c where t.table_name='NODE'

 

 

3、查找重复记录.

  select from  newzj.t533to555 a

 where a.rowid !=

 (

  select max(b.rowid) from newzj.t533to555 b

  where a.id = b.id

     )

 

4、将查询结果存为文件

set   echo   off     

  set   feedback   off     取消数据回显 

  set   heading   off     取消列标题 

  set   linesize   num   你想要的长度 

  set   pagesize   num   一页的行数 

  spool   c:\文件名 

  select   *   from   marc_data 

  spool   off 

SQL>@c:\test.sql   是运行脚本 

 

5、如何定位SESSIOIN

跟踪SESSION的一点小窍门

不知道大家知不知道的,在这里随便提一下吧。

有的时候在本机上开了多个sqlplus窗口,想跟踪其中一个,却发现无从查起,不知道哪个SESSION才是自己的。后来查了一下文档,发觉有个CLENT_INFO可以做标志的。

 

Microsoft Windows 2000 [Version 5.00.2195]

(C) 版权所有 1985-2000 Microsoft Corp.

 

C:\Documents and Settings\Administrator>sqlplus

 

SQL*Plus: Release 9.2.0.1.0 - Production on 星期五 2 4 10:21:05 2005

 

Copyright (c) 1982, 2002, Oracle Corporation. All rights reserved.

 

请输入用户名: / as sysdba

 

连接到:

Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.1.0 - Production

 

SQL> begin

2 DBMS_APPLICATION_INFO.SET_CLIENT_INFO ('winy');

3 end;

4 /

 

PL/SQL 过程已成功完成。

 

SQL> select sid,client_info from v$session;

 

SID CLIENT_INFO

---------- -------------------------------------

1

2

3

4

5

6

7

8

9 winy

10

 

已选择10行。

 

SQL>

 

标识可以自己随便定义,这样就算数据库中有再多的SESSION也不怕啦,呵呵。

 

 

6、如何减少TEMP表空间

C:\Documents and Settings\Administrator>sqlplus

 

SQL*Plus: Release 9.2.0.4.0 - Production on 星期五 2 27 16:54:17 2009

 

Copyright (c) 1982, 2002, Oracle Corporation.  All rights reserved.

 

请输入用户名:  system@oa

请输入口令:

 

连接到:

Oracle9i Enterprise Edition Release 9.2.0.4.0 - Production

With the Partitioning, OLAP and Oracle Data Mining options

JServer Release 9.2.0.4.0 - Production

 

SQL>

SQL> alter database tempfile '/u01/oracle/oradata/orah80/temp03.dbf' drop;

 

数据库已更改。

 

SQL> alter tablespace temp2 add tempfile '/u01/oracle/oradata/orah80/temp03.dbf'

 size 2048m reuse autoextend on next 100m;

 

表空间已更改。

 

SQL>

 

 

7、缩小UNDO表空间

SQL> create undo tablespace undots2

  2  datafile '/oracle/oradata/test/undots2.dbf'

  3  size 10M autoextend on;

 

Tablespace created.

 

SQL>

 

SQL> show parameter undo

 

NAME                                 TYPE        VALUE

------------------------------------ ----------- ------------------------------

undo_management                      string      AUTO

undo_retention                       integer     900

undo_tablespace                      string      UNDOTBS1

SQL> alter system set undo_tablespace='UNDOTS2';

 

System altered.

SQL> drop tablespace undotbs1 including contents and datafiles;

 

Tablespace dropped.

 

SQL>

 

 

8、帐户名与安全标识间无任何映射完成(windows)

windows下帐户名与安全标识间无任何映射完成

把服务里的sql server agent的登录改成administrator

 

 

9、ORACLE查IP地址

listener.log可以看到主机名及IP地址。
netstat -an也可以看到一些信息。
cat listener.log|grep SHEBEI1 |more

 

阅读(810) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~