SELECT table_name FROM user_tables;
select user,table_name from all_tables;
select table_name,column_name from user_tab_columns;
select user,table_name,column_name from all_tab_columns;
select * from user_sequences;
-- 查询所有的用户生成的ORACLE对象
SELECT * FROM user_objects;
select table_name,comments from user_tab_comments;
select table_name,column_name,comments from user_col_comments;
COMMENT ON TABLE aa10 IS '系统参数表';
COMMENT ON COLUMN aa10.aaa100 IS '参数类别';
DESC aa10;
-- 通过系统表,查看表中列的属性,包括 数据类型,是否非空等
SELECT table_name,COLUMN_ID,column_name,data_type,data_length, DATA_PRECISION,NULLABLE
FROM user_tab_columns
ORDER BY table_name,COLUMN_ID;
-- 查看数据库中表、索引占用的数据库空间大小
SELECT * FROM user_segments;
CREATE TABLE table_count(table_name VARCHAR2(50),columns NUMBER(20));
-- 通过PB运行下面的语句,得到结果集,将结果集在PB下执行,最后提交
select 'insert into table_count values('''||table_name||''', (select count(1) from '||table_name||'));//'||comments from user_tab_comments;
-- 所有表的记录都在table_count了
SELECT * FROM table_count;
DELETE FROM PBCATCOL WHERE PBC_TNAM LIKE '%';
DELETE FROM PBCATTBL WHERE PBT_TNAM LIKE '%';
INSERT INTO PBCATTBL
( PBT_TNAM,
PBT_OWNR ,
PBT_CMNT)
SELECT ALL_TAB_COMMENTS.TABLE_NAME,
ALL_TAB_COMMENTS.OWNER,
ALL_TAB_COMMENTS.COMMENTS
FROM ALL_TAB_COMMENTS
WHERE ALL_TAB_COMMENTS.OWNER = 'LH'
AND TABLE_NAME LIKE '%';
// 同步字段名
( PBC_TNAM,
PBC_OWNR,
PBC_CNAM,
PBC_LABL,
PBC_CMNT,
PBC_HDR)
SELECT ALL_COL_COMMENTS.TABLE_NAME,
ALL_COL_COMMENTS.OWNER,
ALL_COL_COMMENTS.COLUMN_NAME,
ALL_COL_COMMENTS.COMMENTS ,
ALL_COL_COMMENTS.COMMENTS ,
ALL_COL_COMMENTS.COMMENTS
FROM ALL_COL_COMMENTS
WHERE ALL_COL_COMMENTS.OWNER = 'LH'
AND TABLE_NAME LIKE '%';
-- 将ORACLE数据库的注释同步到PB中 代码结束
--将PB注释同步到ORACLE中
select 'comment on table '||pbt_tnam||' is '''||pbt_cmnt||''';' from pbcattbl where pbt_tnam not like 'PB%'
UNION
select 'comment on column '||pbc_tnam||'.'||pbc_cnam||' is '''||pbc_cmnt||''';' from pbcatcol where pbC_tnam not like 'PB%';
--查进程
select object_id,session_id,locked_mode from v$locked_object;
from v$locked_object t1,v$session t2
where t1.session_id=t2.sid order by t2.logon_time;
--杀进程
alter system kill session '3,6666';
1、查找表的所有索引(包括索引名,类型,构成列):
select t.*,i.index_type from user_ind_columns t,user_indexes i wheret.index_name = i.index_name and t.table_name = i.table_name and t.table_name = 要查询的表
2、查找表的主键(包括名称,构成列):
select cu.* from user_cons_columns cu, user_constraints au wherecu.constraint_name = au.constraint_name and au.constraint_type = 'P' andau.table_name = 要查询的表
3、查找表的唯一性约束(包括名称,构成列):
select column_name from user_cons_columns cu, user_constraints au wherecu.constraint_name = au.constraint_name and au.constraint_type = 'U' andau.table_name = 要查询的表
4、查找表的外键(包括名称,引用表的表名和对应的键名,下面是分成多步查询):
select * from user_constraints c where c.constraint_type = 'R' and c.table_name= 要查询的表
查询外键约束的列名:
select * from user_cons_columns cl where cl.constraint_name = 外键名称
查询引用表的键的列名:
select * from user_cons_columns cl where cl.constraint_name = 外键引用表的键名
5、查询表的所有列及其属性
select t.*,c.COMMENTS from user_tab_columns t,user_col_comments c wheret.table_name = c.table_name and t.column_name = c.column_name and t.table_name= 要查询的表
6、Oracle中每个用户表的表名和行数
select table_name,num_rows fromuser_tables;
7、Oracle查询用户表空间:select * from user_all_tables
8、Oracle查询所有函数和储存过程:select *from user_source
9、Oracle查询所有用户:
select *from all_users;
select *from dba_users
10、Oracle查看当前用户连接:select * fromv$Session
11、Oracle查看当前用户权限:select * fromsession_privs
12、Oracle查看用户表空间使用情况:
select a.file_id"FileNo",a.tablespace_name
"Tablespace_name",
a.bytes "Bytes",a.bytes-sum(nvl(b.bytes,0))"Used",
sum(nvl(b.bytes,0)) "Free",
sum(nvl(b.bytes,0))/a.bytes*100"%free"
from dba_data_files a, dba_free_space b
where a.file_id=b.file_id(+)
group by a.tablespace_name ,
a.file_id,a.bytes order by a.tablespace_name;