Oracle中查询各种对象的方法小结
--查看当前库中的所有表
select * from all_tables a where a.table_name='INFOCODE_P20081'
--查看表结构
select * from all_tab_columns where table_name='INFOCODE_P20081'
--查看触发器、过程、函数
select * from user_source;
select COUNT(*) from user_source WHERE TYPE='PROCEDURE';
select * from user_triggers;
--获取有哪些用户在使用数据库
select username from v$session;
--怎样查得数据库的SID
select name from v$database;
--如何在Oracle服务器上通过SQLPLUS查看本机IP地址 ?
select sys_context('userenv','ip_address') from dual;
--数据库有多少个tablespace
select * from dba_tablespaces;
--如何查有多少个数据库实例?
SELECT * FROM V$INSTANCE;
--查询当前用户对像?
SELECT * FROM USER_OBJECTS;
SELECT * FROM DBA_SEGMENTS;
--如何知道用户拥有的权限?
SELECT * FROM dba_sys_privs ;
--查询表空间信息?
SELECT * FROM DBA_DATA_FILES;
--------------------------------------------------------------------------------------------------------------------
--查询被锁表的方法:
SELECT S.SID SESSION_ID, S.USERNAME, DECODE(LMODE, 0, 'None', 1, 'Null', 2, 'R
ow-S (SS)', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X (SSX)', 6, 'Exclusive', TO_CHAR(LMODE)) MODE_HELD, DECODE(REQUEST, 0, 'None', 1, 'Null', 2, 'Row-S (SS)
', 3, 'Row-X (SX)', 4, 'Share', 5, 'S/Row-X (SSX)', 6, 'Exclusive', TO_CHAR(REQUEST)) MODE_REQUESTED, O.OWNER||'.'||O.OBJECT_NAME||' ('||O.OBJECT_TYPE||')',
S.TYPE LOCK_TYPE, L.ID1 LOCK_ID1, L.ID2 LOCK_ID2 FROM V$LOCK L, SYS.DBA_OBJECTS O, V$SESSION S WHERE L.SID = S.SID AND L.ID1 = O.OBJECT_ID ;
--如何解锁
ALTER SYSTEM KILL SESSION 'SID,SERIR#';
--如何获取链接状况
SELECT * FROM DBA_DB_LINKS;
--给表、列加注释
comment on table 表 is '表注释';
comment on column 表.列 is '列注释';
select * from user_tab_comments where comments is not null;
--在ORACLE中取毫秒
select systimestamp from dual;
--如何在字符串里加回车
select 'Welcome to visit'||chr(10)||'www.CSDN.net' from dual ;
--如何将小表放入keep池中
alter table xxx storage(buffer_pool keep);
--如何查看现有回滚段及其状态
--col segment format a30
SELECT SEGMENT_NAME,OWNER,TABLESPACE_NAME,SEGMENT_ID,FILE_ID,STATUS FROM
DBA_ROLLBACK_SEGS
--ORACLE产生随机函数
select DBMS_RANDOM.RANDOM from dual
--第一个是查字段注释
select * from user_col_comments where table_name='表名(大写)';
--第二个是查表的注释
select * from USER_TAB_COMMENTS where table_name='表名(大写)';