分类: Oracle
2013-04-02 09:57:25
原文地址:常用sql语句 作者:ning_lianjie
select count(*) from sh.times;
从表student01的B列中,查找不重复的数据select distinct B from student01;
复制表create table time_hz tablespace xing1228 as select * from sh.times
将A列的数值加1,但是原始数据库中不变select a+1,b from student01;
select a,(a+1) bieming,b from student01;
查看当前用户所有表名select unique tname from col;
查看还没有提交的事务select * from v$locked_object;
select * from v$transaction;
查看当前所有对象select * from tab;
查看当前会话的SID和serialSELECT Sid, Serial#
FROM V$session
WHERE Audsid = Sys_Context('USERENV', 'SESSIONID');
查询当前时间select to_char(sysdate,'yyyy-mm-dd,hh24:mi:ss') from dual;
使用sqlplus计算select 256*256 from dual;
通过授权方式来创建用户grant connect,resource to nlj identified by "123456";
用户之间复制数据create table dep (dep number(2) not null, dname char(14), loc char(13));
找出未断开的连接select process,osuser,username,machine,logon_time ,sql_text
from v$session a,v$sqltext b
where a.sql_address=b.address;
查看表空间名称及大小(MB)select t.tablespace_name, round(sum(bytes/(1024*1024)),0) ts_size
from dba_tablespaces t, dba_data_files d
where t.tablespace_name = d.tablespace_name
group by t.tablespace_name;
查看表空间对应的物理文件位置及大小select tablespace_name, file_id, file_name,round(bytes/(1024*1024),0) total_space
from dba_data_files
order by tablespace_name;
查看UNDO段select segment_name, tablespace_name, r.status,(initial_extent/1024) InitialExtent,(next_extent/1024) NextExtent,max_extents, v.curext CurExtent
From dba_rollback_segs r, v$rollstat v
Where r.segment_id = v.usn(+)
order by segment_name ;
查看表空间使用情况select sum(bytes)/(1024*1024) as free_space,tablespace_name
from dba_free_space
group by tablespace_name;
查看oracle版本Select version FROM Product_component_version
Where SUBSTR(PRODUCT,1,6)='Oracle';
查看数据库创建时间和归档方式Select Created, Log_Mode, Log_Mode From V$Database;
捕捉运行很久的SQL语句(TOP SQL)select username,sid,opname,
round(sofar*100 / totalwork,0) '%' as progress,time_remaining,sql_text
from v$session_longops , v$sql
where time_remaining <> 0
and sql_address = address and sql_hash_value = hash_value