oracle如何区分 64-bit/32bit 版本
select * from v$version;
请问如何分辨某个用户是从哪台机器登陆oracle的?
select machine , terminal from v$session;
查询表及字段
select * from all_tables where table_name like '%'
select * from all_tab_columns where table_name='??'
怎样得到触发器、过程、函数的创建脚本?
user_source
user_triggers
怎样计算一个表占用的空间的大小?
select owner,table_name,
num_rows,
blocks*aaa/1024/1024 "size m",
empty_blocks,
last_analyzed
from dba_tables
where table_name='xxx';
Here: AAA is the value of db_block_size ;
XXX is the table name you want to check
怎么获取有哪些用户在使用数据库
select username from v$session;
怎样查得数据库的SID ?
select name from v$database;
如何查询每个用户的权限?
select * from dba_sys_privs;
如何将表移动表空间?
alter table table_name move tablespace_name;
如何将索引移动表空间?
alter index index_name rebuild tablespace tablespace_name;
LINUX下查询磁盘竞争状况命令?
sar -d
LINUX下查询CPU竞争状况命令?
sar -r
如何查看各个表空间占用磁盘情况?
select
b.file_id 文件ID号,
b.tablespace_name 表空间名,
b.bytes 字节数,
(b.bytes-sum(nvl(a.bytes,0))) 已使用,
sum(nvl(a.bytes,0)) 剩余空间,
sum(nvl(a.bytes,0))/(b.bytes)*100 剩余百分比
from dba_free_space a,dba_data_files b
where a.file_id=b.file_id
group by b.tablespace_name,b.file_id,b.bytes
order by b.file_id
怎么可以快速做一个和原表一样的备份表?
create table new_table as (select * from old_table);
如何快速清空一个大表?
truncate table table_name;
怎么把select出来的结果导到一个文本文件中?
SQL>SPOOL C:/ABCD.TXT;
SQL>select * from table;
SQL >spool off;
如何修改表名?
alter table old_table_name rename to new_table_name;
怎样用Sql语句实现查找一列中第 N大值?
select * from (select t.*,dense_rank() over (order by sal) rank from employee) where rank = N;
统计信息更新
exec dbms_stats.gather_schema_stats(ownname => 'XXX',options => 'GATHER',estimate_percent => dbms_stats.auto_sample_size,method_opt => 'for all columns size repeat',degree => 15)
查询外键约束
select * from user_constraints where constraint_type='R';
禁用
alter table BBSCS_USERDETAIL disable constraint FK_NAME;
启用
alter table BBSCS_USERDETAIL enable constraint FK_NAME;