describe TABLE_NAME; --描述
----------------------------------------------------------------
create table as select XXXXXX
insert into TABLE_NAME (reac_1,reac_2.....) values(v1,v2)
insert into TABLE_NAME (select * from ..........)
update TABLE_NAME set reac_1=v1,................... where .....
delete from TABLE_NAME where ...................
----------------------------------------------------------------
select [all|distinct top n[percent]] with ties SELECT_LIST
[into[NEW_TABLE_NAME]]
[from {TABLE_NAME,....}][(OPTIMIZWE_HINTS)]
[where CLAUSE]
[group by CLAUSE]
[order by CLAUSE]
[compute CLAUSE]
[for browse]
--distinct 检索唯一的表列值
----------------------------------------------------------------
= != <> like and or between XXX and XXX in(XX,XX) union (合并查询)
----------------------------------------------------------------
alter table TABLE_NAME add REAC_NAME REAC_TYPE --改变列(添加列)
EG: alter table scott.emp add name_my char(10) NULL;
alter table TABLE_NAME modify(name_my char(10)) --改变列长度
alter table TABLE_NAME DROP COLUMN name_my --drop列
--------------------------
--函数-----------
---------------------------
asin() 反正玄 acos()反余玄 atan()反正切 atb2(,)反正切
sin()正玄 cos()余玄 tan()正切 cot()余切
exp()指数 power(a,b)a的b次方根 sort()平方根 square()平方
log()自然对数 log10()对数 abs()绝对值
ceiling(a)大于a的最小整数 floor(a)小于a的最大整数
rand()0-1的随机数 pi()3.14159 sign(a) a<0,=0,>0时,返回-1,0,1
count()合计 sum()求和 max() min()
----------------------------------------------------------------
ascii()求asc值 unicode()求unicode值 initcap()首字母变大写
str(a,l,d)转化为字符串,a为数值,l为长,d为保留小数位数
len()求长 left(a,l) right(a,l) lower()变小写 upper()变大写
ltrim()删除字符串前导空格 rtrim()删除字符串尾部空格
--------------------------------------------------------------------
sysdate()当前日期 last_day()本月最后一天 add_months(d,n)d后n个月
union 连接两个数据集
------------------------
--v$视图
------------------------
select * from v$parameter; --察看init.orc的配置参数
select * from v$controlfile; --列出server正在使用的控制文件
select * from v$log; --联机重做日志文件信息
select * from v$datafile --数据库使用的数据文件信息
select * from v$librarycache --共享池中sql管理信息
select * from v$lock --锁的信息
select * from v$parameter --进程信息
select * from v$rollname --回滚段信息
select * from v$rollstat --回滚段统计
select * from v$session --会话信息
------------------
--dba视图
-----------------
select * from dba_tablespaces --表空间信息
select * from dba_extents --数据区信息
select * from dba_tables --表信息
select * from dba_rollback_segs --回滚段
select * from dba_segments --段空间分配情况
select * from dba_views --视图信息
select * from dba_sequences --序列信息
select * from dba_triggers --触发器
select * from dba_synonyms --同义词
select * from dba_db_like --数据连接
select * from dba_objects
select * from dba_source --函数,包,过程信息
select * from dba_data_files --文件信息
select * from dba_free_space --表中自由分区
---------------------------------------
--与权限相关的dba视图
--------------------------------------
select * from dba_roles --角色名及其口令状态
select * from dba_roles_privs --已被授予角色的用户
select * from dba_sys_privs --已被授予系统权限的用户
select * from dba_tab_privs --已被授予表中权限的用户
select * from dba_col_privs --已被授予列中权限的用户
select * from role_role_privs --已被授予其他角色的角色
select * from role_sys_privs --已被授予系统权限的角色
select * from role_tab_privs --已被授予表中权限的角色
select * from session_privs --系统启用的权限
select * from session_roles --系统启用的角色
select
Username,
Password
from DBA_USERS --用户及其密码
-------------------
--审计
---------------------
select * from dba_audit_session; --查询审计
select * from DBA_AUDIT_OBJECT; --对象审计
select
Action,
Name
from AUDIT_ACTIONS; --显示审计类型代码
---------------------
--连接qracle
----------------------
sqlplusw /nolog
connect username/password as sysdba
-------------------
--启动数据库
-------------------
--初始化参数文件位置 win:' $?/dbs' ,unix :'$?/database'
--检查顺序:
----spfile$ORAC_SID.ora
----spfile.ora
----init$ORAC_SID.ora
startup --正常启动
startup pfile=c:/oracle/database/text_spfile.ora --用 XXX.ora初始化实例
startup nomount --不装载数据库
startup mount --只连接数据库,不打开它
startup restrict --限制访问数据库
startup force --强迫启动
startup open recover --启动,并启动完整的介质恢复过程.
------------------------
--改变数据库状态
-------------------------
alter database mount --装载数据库
alter database open --打开数据库
alter database open read only --只读打开
alter database open read write --读写打开(默认)
-----------------------
--关闭数据库
---------------------
shutdown normal --普通模式
shutdown immediate --立即模式
shutdown transactional --立即模式
shutdown abort --强制(需要介质恢复)
----------------------------
--禁止操作数据库
-----------------------------
alter system quiesce restricted ; --将数据库设为静止状态
alter system unquiesce ; --设为操作状态
select * from v$instance; --察看实例当前状态
--normal 操作状态
--quiescing 静止,激活
--quiesced 静止,非激活
---------------------------
--暂停数据库
--------------------------
alter system suspend; --暂停数据库
alter system resume; --继续数据库
-------------------
--新建用户
-------------------
CREATE USER &USER_NAME --用户名
--PROFILE &DEFAULT --慨要文件
IDENTIFIED BY &PASSWORD --密码
DEFAULT TABLESPACE &&TABLESPACE --表空间
temporary tablespace &&TEMP_SPACE; --临时表空间
QUOTA 10M ON &&TABLESPACE --使用表空间的配额
QUOTA 15M ON &&TEMP_SPACE --使用表空间的配额
ACCOUNT UNLOCK --非锁定
password expire; --强制口令过期
-------------------
--赋权限
-------------------
GRANT Connect,Exp_Full_Database To &user_name;
-----------------
--撤销权限
-------------------
revoke delete on TABLE_NAME from NAME
revoke all on TABLE_NAME from NAME
-----------------
--撤销角色
-------------------
revoke ROLE_NAME from NAME
-------------------
--删除用户
-------------------
drop user &user_naem;
drop user &user_name cascade; --将对象一起删除
-------------------
--修改用户
-------------------
alter user &USER_NAME --用户名
PROFILE &DEFAULT
IDENTIFIED BY &PASSWORD --密码
DEFAULT TABLESPACE &&TABLESPACE --表空间
temporary tablespace &&TEMP_SPACE --临时表空间
QUOTA 10M ON &&TABLESPACE --使用表空间的配额
QUOTA 15M ON &&TEMP_SPACE --使用表空间的配额
ACCOUNT UNLOCK --非锁定
password expire; --强制口令过期
--配置用户在表空间使用情况
alter user &USER_NAME quota 0 on &TABLESPACE_NAME;
alter user &USER_NAME quota 100M on &TABLESPACE_NAME;
--强制口令过期
alter user &USER_NAME password expire;
-------------------------
--设置加密口令
-------------------------
alter user &USER_NAME IDENTIFIED BY values '1A1A1A1A1A1A1A1A'
------------------------
--创建角色,并赋权限
-------------------------
create role &ROLE_NAME;
grant CREATE SESSION,CREATE USER,ALTER USER to &ROLE_NAME;
-------------------------------------
--登录失败为3次,锁定10天
-------------------------------------
alter profle &USER_NAME limit failed_login_attempts 3 password_lock_time 10;
-------------------------------------
--新建慨要文件
-------------------------------------
create profile &DEFAULT_NAME limit
PASSWORD_LIFE_TIME UNLIMITED ; --有效期
-------------------------------------
--修改慨要文件
-------------------------------------
ALTER PROFILE &DEFAULT_NAME LIMIT --慨要文件名(P238)
SESSION_PER_USER UNLIMITED --一个用户可同时拥有的会话
CPU_PER_SESSION UNLIMITED --一个会话可用cpu时间(1/100秒)
CPU_PER_CALL UNLIMITED --一个调用可用cpu时间(1/100秒)
CONNECT_TIME UNLIMITED --一个会话连接时间(分钟数)
idle_time UNLIMITED --一个会话的空闲时间(分钟数)
LOGICAL_READS_PER_SESSION UNLIMITED --一个会话可读取的数据块数
LOGICAL_READS_PER_CALL UNLIMITED --一个调用读取的数据块数
PRIVATE_SGA UNLIMITED --共享池私人空间
COMPOSITE_LIMIT UNLIMITED --复合验证
PASSWORD_LIFE_TIME UNLIMITED --有效期
PASSWORD_GRACE_TIME UNLIMITED --实效后锁定天数
PASSWORD_REUSE_TIME UNLIMITED --口令重新使用必须经历的天数()
PASSWORD_REUSE_MAX UNLIMITED --口令重新使用必须经历的次数()
FAILED_LOGIN_ATTEMPTS UNLIMITED --几次登录失败后锁定
PASSWORD_LOCK_TIME UNLIMITED --锁定时间(天)
PASSWORD_VERIFY_FUNCTION NULL; --口令复杂性函数
--------------
--检索
-------
REM 显示那些系统权限给了那些角色
select
Role, /*Name of the role*/
Privilege, /*System privilege*/
Admin_Option /*Was admin option granted?*/
from ROLE_SYS_PRIVS;
REM 显示授权和通过角色的授权
select
Grantee, /*Recipient of the grant*/
Owner, /*Owner of the object*/
Table_Name, /*Name of the object*/
Grantor, /*User who made the grant*/
Privilege, /*Privilege granted*/
Grantable /*Was admin option granted?*/
from DBA_TAB_PRIVS;
REM 通过角色的授权
select
DBA_ROLE_PRIVS.Grantee, /*Recipient of the grant*/
ROLE_TAB_PRIVS.Owner, /*Owner of the object*/
ROLE_TAB_PRIVS.Table_Name, /*Name of the object*/
ROLE_TAB_PRIVS.Privilege, /*Privilege granted*/
ROLE_TAB_PRIVS.Grantable /*Was admin option granted?*/
from DBA_ROLE_PRIVS, ROLE_TAB_PRIVS
where DBA_ROLE_PRIVS.Granted_Role = ROLE_TAB_PRIVS.Role
and DBA_ROLE_PRIVS.Grantee = 'some username';
alter tablespace &tablespace_name temporary --指定表空间为临时段空间
alter tablespace &tablespace_name permanent --指定表空间为正常表空间
------------------------
--修改表空间
--------------------------
alter tablespace &tablespace_name --表空间名
datafile 'C:/XXX/XXX.dbf' size 200m --表空间大小
autoextend on --是否自动增长
next 10m --以多少进行自我扩展
maxsize 250m --表空间最大值
-----------------------------------
--在表空间中添加文件
-----------------------------------
alter tablespace &tablespace_name --表空间名
add datafile 'C:/XXX/XXX.dbf' --文件名
size 200m --表空间大小
autoextend on --是否自动增长
next 10m --以多少进行自我扩展
maxsize 250m --表空间最大值
----------------------
--移动表空间(1)
------------------------
svrmgr>shutdown;
svrmgr>exit
#mv XX XX
svrmgr>startup mount MAINDB;
svrmgr>alter database rename file
2>'c:/XX/XX' to
3>'D:/xx/xx/';
svrmgr>alter database open;
----------------------
--移动表空间(2)
----------------------
svrmgr>alter database &tablespace_name offline --设置表空间为脱机状态
#mv XX XX --移动文件
svrmgr>alter tablespace &TABLESPACE_NAME rename datafile
2>'c:/XX/XX' to
3>'D:/xx/xx/'; --更改文件
svrmgr>alter database &tablespace_name online --设置表空间为联机状态
-----------------
--回滚段
-----------------
alter rollback segment &SEGMENT_NAME offline; --设置回滚段离线
alter rollback segment &SEGMENT_NAME online; --设置回滚段在线
drop rollback segment &SEGMENT_NAME; --删除回滚段
create rollback segment &SEGMENT_NAME tablespace &tablespace_name; --新建回滚段
--新建后列入init.ora
--rollback_segment=(r0,r1,r2)
select * from v$rollstat --查看回滚段情况
alter rollback segment &SEGMENT_NAME shrink [to 15m] --收缩回滚段
--------------------
--回滚段中的事务查询
--------------------
REM Users in rollback segments
REM
column rr heading 'RB Segment' format a18
column us heading 'Username' format a15
column os heading 'OS User' format a10
column te heading 'Terminal' format a10
select R.Name rr,
nvl(S.Username,'no transaction') us,
S.Osuser os,
S.Terminal te
from V$LOCK L, V$SESSION S, V$ROLLNAME R
where L.Sid = S.Sid(+)
and trunc(L.Id1/65536) = R.USN
and L.Type = 'TX'
and L.Lmode = 6
order by R.Name;
--------------------------
--查询写入回滚段的字节数
-------------------------
REM Cumulative bytes written to a rollback segment
select
N.Name, /* rollback segment name */
S.Writes /* bytes written to date */
from V$ROLLNAME N, V$ROLLSTAT S
where N.USN=S.USN;
---------------------
--清空回滚段
-------------------
-- clear undo begin
alter system set undo_tablespace = '';
DROP TABLESPACE "UNDOTBS" INCLUDING CONTENTS AND DATAFILES CASCADE CONSTRAINTS;
CREATE UNDO TABLESPACE "UNDOTBS"
DATAFILE '/oracle/oradata/test/UNDOTBS.dbf' SIZE 6000M;
alter system set undo_tablespace = 'UNDOTBS';
-- clear undo end
--导出
exp system/manager file=expdat.dmp compress=Y owner=(HR,THUMPER)
------------------------------------------------
--察看用户在那个表空间拥有对象
------------------------------------------------
set pagesize 60
break on Owner on Tablespace_Name
column Objects format A20
select
Owner,
Tablespace_Name,
COUNT(*)||' tables' Objects
from DBA_TABLES
where Owner <> 'SYS'
group by
Owner,
Tablespace_Name
union
select
Owner,
Tablespace_Name,
COUNT(*)||' indexes' Objects
from DBA_INDEXES
where Owner <> 'SYS'
group by
Owner,
Tablespace_Name
spool user_locs.lst
/
spool off
-----------------------------------------------
--察看表空间拥有的用户对象
-----------------------------------------------
set pagesize 60
break on Tablespace_Name on Owner
column Objects format A20
select
Tablespace_Name,
Owner,
COUNT(*)||' tables' Objects
from DBA_TABLES
where Owner <> 'SYS'
group by
Tablespace_Name,
Owner
union
select
Tablespace_Name,
Owner,
COUNT(*)||' indexes' Objects
from DBA_INDEXES
where Owner <> 'SYS'
group by
Tablespace_Name,
Owner
spool ts_locs.lst
/
spool off
---------------------------
--搜索第三方权限
-----------------------------
select
Grantor, /*Account that made the grant*/
Owner, /*Account that owns the table*/
Table_Name, /*Name of the table*/
Grantee, /*Account granted access*/
Privilege, /*Privilege granted*/
Grantable /*Granted with admin option?*/
from DBA_TAB_PRIVS
where Grantor ! = Owner
order by Grantor, Owner, Table_Name, Grantee, Privilege;
----------------------------------------------------
--搜索索引拥有者和表拥有者有无相同记录
----------------------------------------------------
select
Owner, /*Owner of the index*/
Index_Name, /*Name of the index*/
Table_Owner, /*Owner of the table*/
Table_Name /*Name of the indexed table*/
from DBA_INDEXES
where Owner != Table_Owner
----------------------------
--联机备份
------------------------------
-----------------------------------------------切换到归档模式
SVRMGR> connect sys as sysdba;
SVRMGR> startup mount oarc;
SVRMGR> alter database archivelog;
SVRMGR> archive log start ; --启用自动存档
SVRMGR> alter database open;
-----------------------------------------------察看档案模式
SVRMGRl> archive log list
-----------------------------------------------通过视图察看档案模式
select Name,
Value
from V$PARAMETER
where Name like 'log_archive%';
-----------------------------------------------切换到不归档模式
SVRMGR> connect sys as sysdba;
SVRMGR>startup mount orac;
SVRMGR> alter database noarchivelog;
SVRMGR> alter database open;
-----------------------------------------------察看数据库文件
select file_name from dba_data_files;
-----------------------------------------------开始联机备份
alter tablespace &tablespace_name begin backup
-----------------------------------------------结束联机备份
alter tablespace &tablespace_name end backup
-----------------------------
--不完全恢复
------------------------------
startup mount ;
recover database ;
alter database open ;
-----------------------------------------------基于cancel的恢复
startup mount ;
recover database until cancel;
alter database open resetlogs; --复位数据库
-----------------------------------------------基于时间的恢复
startup mount ;
recover database until time '2 月-20-2004,08:17:48';
recover database until time 'YYYY-MM-DD:HH24:MI:SS';
alter database open resetlogs;
-----------------------------------------------基于scn的恢复
select recid,stamp,first_change#,first_time,next_change# from V$log_history; --察看scn历史
startup mount ;
recover database until change 40000000;
alter database open resetlogs;
-----------------------------------------------使用备份的控制文件恢复
startup mount ;
recover database using backup controlfie;
alter database open ;
-------------------------------
--自动生成备份命令--
------------------------------
-----------------------------------------------begin backup
select
'alter tablespace '||Tablespace_Name||' begin backup;'
from DBA_TABLESPACES
where Status <> 'INVALID';
-----------------------------------------------end backup
select
'alter tablespace '||Tablespace_Name||' end backup;'
from DBA_TABLESPACES
where Status <> 'INVALID'
------------------------
--备份控制文件--
------------------------
alter database backup controlfile to 'xxxxxxxx/xx.bat'
alter database backup controlfile to trace;
-------------------------------
--归档重做日志备份--
-------------------------------
archive log stop ;
move XX XX
archive log start;
------------------------------------------
--创建重做日志 ..(组名为, 5)--
------------------------------------------
SVRMGR>alter database add logfile group 5 ('C:/Oracle/ORADATA/orac/log_1c.dbf','C:/Oracle/ORADATA/orac/log_2c.dbf') size 5m
------------------------------------------------
--添加日志文件到已经存在的组--
------------------------------------------------
SVRMGR>alter database add logfile member 'C:/Oracle/ORADATA/orac/log.dbf' to group 4
--------------------------------------------------------------------------------------------------------------------------
--在sqlplus 中创建日志 --
--sql>alter database add logfile group 5 --
--('C:/Oracle/ORADATA/orac/log_1c.dbf','C:/Oracle/ORADATA/orac/log_2c.dbf') size 5m --
-- --
--sql>alter database add logfile member 'C:/Oracle/ORADATA/orac/log.dbf' to group 4 --
--------------------------------------------------------------------------------------------------------------------------
------------------------------------------
--移动日志文件
------------------------------------------
SVRMGR>shutdown
mv XX XX
SVRMGR>startup mount MAINDB;
SVRMGR>alter database remane file
2>'XXXX' to
3>'XXXX'
SVRMGR>alter database open;
------------------------------------------
--移动控制文件
------------------------------------------
SVRMGR>shutdown
mv XX XX
--编辑init.ora .config.ora 中
--control_files(/xx/xx/xx1.ctl,
/xx/xx/xx2.ctl)
SVRMGR>startup
----------------------
--设置允许审计
---------------------------
--在init.ora中 audit_trail =none/db/os
--禁止审计/审计写入sys.aud$/审计写入操作系统跟踪文件.
-------------------
--登录审计
--------------------
audit session;
audit session whenever successful; --只审计成功连接企图
audit session whenever not successful; --只审计失败连接企图
-------------------
--审计查询
--------------------
select * from sys.aud$
select * from dba_audit_session; --连接审计
select * from DBA_AUDIT_OBJECT; --对象审计
--常用查旬(连接审计)
select
OS_Username, /*Operating system username used.*/
Username, /*Oracle username of the account used.*/
Terminal, /*Terminal ID used.*/
DECODE(Returncode,'0','Connected',
'1005','FailedNull',
'1017','Failed',Returncode) as Failure_check, /*Failure check*/
TO_CHAR(Timestamp,'DD-MON-YY HH24:MI:SS') as Login_time, /*Login time*/
TO_CHAR(Logoff_Time,'DD-MON-YY HH24:MI:SS') as Logoff_time /*Logoff time*/
from DBA_AUDIT_SESSION;
--常用查旬(对象审计)
select
OS_Username, /*Operating system username used.*/
Username, /*Oracle username of the account used.*/
Terminal, /*Terminal ID used.*/
Owner, /*Owner of the affected object.*/
Obj_Name, /*Name of the affected object.*/
Action_Name, /*Numeric code for the action.*/
DECODE(Returncode,'0','Success',Returncode) as type ,
TO_CHAR(Timestamp,'DD-MON-YYYY HH24:MI:SS') as Timestamp
from DBA_AUDIT_OBJECT;
--------------------
--操作审计
------------------------
noaudit session; --禁止会话审计
audit session; --启用会话审计
noaudit role;
audit role; --审计所有系统级命令并且提供命令组
--其他审计项目
----------------------------------------------
counect --审计登录,注销
dba --审计dba命令
resource --审计对象命令
all --审计以上所有
all privileges --审计全部
--------------------------------------------------------
----------------------------
--显示审计类型代码
----------------------------
select
Action, /*Action code.*/
Name /*Name of the action, such as ALTER USER.*/
from AUDIT_ACTIONS;
-------------------------
--审计对象
--------------------------
audit update table by &USER_NAME;
audit all on &OBJ_NAME;
audit insert on &TABLE_NAME by session;
--------------------------
--保护审计
--------------------------
noaudit all on sys.aud$ by access;
---------------
--删除审计
----------------
delete from sys.aud$;
--------------------------------------------
--察看文件
--------------------------------------------
select df.name,(fs.phyblkrd + fs.phyblkwrt) total_io,100*(fs.phyblkrd + fs.phyblkwrt)/maxio weight
from v$filestat fs ,v$datafile df ,
(select max(phyblkrd + phyblkwrt) maxio from v$filestat)
--------------------------------------------
--fsfi值-
--------------------------------------------
-- fsfi=100*sqrt(最大盘区/盘区种空间)*(1/(盘区数1/4))
set newpage 0 pagesize 60
column fsfi format 999.99
select
Tablespace_Name,
SQRT(MAX(Blocks)/SUM(Blocks))*
(100/SQRT(SQRT(COUNT(Blocks)))) Fsfi
from DBA_FREE_SPACE
group by
Tablespace_Name
order by 1
spool fsfi.lis
/
spool off
--------------------------------------------
---自由空间映像
--------------------------------------------
rem
rem file: mapper.sql
rem Parameters: the tablespace name being mapped
rem
rem Sample invocation:
rem @mapper DEMODATA
rem
rem This script generates a mapping of the space usage
rem (free space vs used) in a tablespace. It graphically
rem shows segment and free space fragmentation.
rem
set pagesize 60 linesize 132 verify off
column file_id heading "File|Id"
select
'free space' Owner, /*"owner" of free space*/
' ' Object, /*blank object name*/
File_ID, /*file ID for the extent header*/
Block_ID, /*block ID for the extent header*/
Blocks /*length of the extent, in blocks*/
from DBA_FREE_SPACE
where Tablespace_Name = UPPER('&&1')
union
select
SUBSTR(Owner,1,20), /*owner name (first 20 chars)*/
SUBSTR(Segment_Name,1,32), /*segment name*/
File_ID, /*file ID for extent header*/
Block_ID, /*block ID for block header*/
Blocks /*length of the extent in blocks*/
from DBA_EXTENTS
where Tablespace_Name = UPPER('&&1')
order by 3,4
spool &&1._map.lst
/
spool off
undefine 1
--------------------------------------------
--I/O 权值估计
--------------------------------------------
set pagesize 60 linesize 80 newpage 0 feedback off
ttitle skip center "Database File IO Weights" skip center -
"ordered by Drive" skip 2
column Total_IO format 999999999
column Weight format 999.99
column file_name format A40
break on Drive skip 2
compute sum of Weight on Drive
select
substr(DF.Name, 1,5) Drive,
DF.Name File_Name,
FS.Phyblkrd+FS.Phyblkwrt Total_IO,
100*(FS.Phyblkrd+FS.Phyblkwrt)/MaxIO Weight
from V$FILESTAT FS, V$DATAFILE DF,
(select MAX(Phyblkrd+Phyblkwrt) MaxIO
from V$FILESTAT)
where DF.File# = FS.File#
order by Drive, Weight desc
--------------------------------------------
--回滚段中的活动事务--
--------------------------------------------
column rr heading 'RB Segment' format a18
column us heading 'Username' format a15
column os heading 'OS User' format a10
column te heading 'Terminal' format a10
select R.Name rr,
nvl(S.Username,'no transaction') us,
S.Osuser os,
S.Terminal te
from V$LOCK L, V$SESSION S, V$ROLLNAME R
where L.Sid = S.Sid(+)
and trunc(L.Id1/65536) = R.USN
and L.Type = 'TX'
and L.Lmode = 6
order by R.Name
--------------------------------------------
--察看盘区
--------------------------------------------
select
Tablespace_Name, /*Tablespace name*/
Owner, /*Owner of the segment*/
Segment_Name, /*Name of the segment*/
Segment_Type, /*Type of segment (ex. TABLE, INDEX)*/
Extent_ID, /*Extent number in the segment*/
Block_ID, /*Starting block number for the extent*/
Bytes, /*Size of the extent, in bytes*/
Blocks /*Size of the extent, in Oracle blocks*/
from DBA_EXTENTS
order by Extent_ID;
---------------------
--权限类别 --
---------------------
select delete references(可创建外键)
insert alter execute
update index read(可访问目录)
---------------------
--对象赋权限--
---------------------
grant select on &obj_name to &role_or_user_name --对象赋权限
grant all on &obj_name to public --赋所有权限到所有对象
grant select ,update(&rcd1,&rcd2)
on &obj_name to &role_or_user_name
with grant option; --可以授予其他用户权限
grant &role_name to &user_name; --为用户赋角色
---------------------
--撤销对象权限--
---------------------
revoke delete on &obj_name to &role_or_user_name
revoke all on &obj_name to &role_or_user_name --撤销对象对用户的所有权限
revoke &role_name to &user_name; --撤销对用户的角色授予
-----------
--svrmgr
-----------
-------连接
SVRMGR> connect sys as sysdba
--创建重做日志 ..(组名为, 5)
SVRMGR>alter database add logfile group 5 ('C:/Oracle/ORADATA/orac/log_1c.dbf','C:/Oracle/ORADATA/orac/log_2c.dbf') size 5m
--添加日志文件到已经存在的组
SVRMGR>alter database add logfile member 'C:/Oracle/ORADATA/orac/log.dbf' to group 4
------------------------------------------------------------------------------------------------------------------------
--在sqlplus 中创建undo
--sql>alter database add logfile group 5 --('C:/Oracle/ORADATA/orac/log_1c.dbf','C:/Oracle/ORADATA/orac/log_2c.dbf') size 5m
--
--sql>alter database add logfile member 'C:/Oracle/ORADATA/orac/log.dbf' to group 4
------------------------------------------------------------------------------------------------------------------------
------------------
--联机备份--
------------------
-----------------------------------------------切换到归档模式
SVRMGR> connect sys as sysdba;
SVRMGR> startup mount oarc;
SVRMGR> alter database archivelog;
SVRMGR> archive log start ;
SVRMGR> alter database open;
-----------------------------------------------察看档案模式
SVRMGRl> archive log list
-----------------------------------------------切换到不归档模式
SVRMGR> connect sys as sysdba;
SVRMGR>startup mount orac;
SVRMGR> alter database noarchivelog;
SVRMGR> alter database open;
创建数据字典脚本 @'C:/Oracle/Ora81/RDBMS/ADMIN/SQL.BSQ'
校验口令的复杂性 @C:/Oracle/Ora81/RDBMS/ADMIN/UTLPWDMG.SQL
重建(long_XX_info) 类视图 @C:/Oracle/Ora81/RDBMS/ADMIN/catldr.SQL
创建限制可用命令安全级别 @C:/Oracle/Ora81/sqlplus/admin/pupbld.sql
创建CHAINED_ROWS 表 @C:/Oracle/Ora81/RDBMS/ADMIN/utlchain.sql
------------------------
--合并自由盘区
-------------------------
alter tablespace &SPACE_NAME default storage (pctincrease 1); --调用SMON
alter tablespace &SPACE_NAME coalesce; --手工合并
----------------------------------------------------------------------------------------------------------
alter database datafile 'c:/XXX/XXX.dbf' resize 200m --重定义文件大小
alter database &tablespace_name offline --设置表空间为脱机状态
alter database &tablespace_name online --设置表空间为联机状态
---------------------------------
--强制事务使用回滚段
----------------------------------
set transaction use rollback segment &rollback_name ;
XXXXXXX
---------------------------------
--删除大量数据(不能回滚)
----------------------------------
truncate table &TABLE_NAME ;
truncate table &TABLE_NAME drop storage; --删除表所有数据,释放非初始化空间(缺省)
truncate cluster &CLUSTER_NAME reuse storage --删除簇所有数据
---------------------------------
--删除表中的分区
----------------------------------
alter table &TABLE_NAME
truncate partition &PART_NAME
drop storage;
--------------------
--重建索引
--------------------
alter index &index_name rebuild
stoage (initial 10m next 5m pctincrease 0)
tablespace &tablespace_name
----------------------
--标识连接行--
----------------------
@C:/Oracle/Ora81/RDBMS/ADMIN/utlchain.sql --创建CHAINED_ROWS
analyze table &TABLE_NAME list chained rows into CHAINED_ROWS; --收集表统计信息
select
Owner_Name, /*Owner of the data segment*/
Table_Name, /*Name of the table with the chained rows*/
Cluster_Name, /*Name of the cluster, if it is clustered*/
Head_RowID /*Rowid of the first part of the row*/
from CHAINED_ROWS; --查询信息
--------------
--设置口令文件
----------------------
sys>orapwd file=XXX password=XXX entries=XXXXX
--设置init.ora 中' remote_login_passwordfile = exclusive'
-------------------------------------
--生成还原口令文件的命令
------------------------------------
SELECT 'alter user &&1 identified by values '||''''||
password||''''||' profile '||profile||';'
FROM dba_users WHERE username = upper('&user_name');