计算表的行数count,sh为oracle测试用户,times为该用户下的表
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和serial
SELECT 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";
用户之间复制数据
创建一个表dep,dep列不能为空
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