|
马上注册,结交更多好友,享用更多功能,让你轻松玩转社区。
您需要 登录 才可以下载或查看,没有帐号?立即注册
x
InnoDB数据表的索引,与InnoDB数据表相比,在InnoDB数据表上,索引对InnoDB数据表的重要性要大得多。在InnoDB数据表上,索引不仅会在搜索数据记录时发挥作用,还是数据行级锁定机制的苊、基础。工具
常常碰到必要查找某个工具的界说的情形,上面针对分歧范例的工具分离会商:
1、V$视图和X$视图
一般用户不克不及会见V$视图:
SQL>connlunar/lunar@test1
已毗连。
SQL>select*fromuser_sys_privs;
USERNAMEPRIVILEGEADMIN_OPTION
----------------------------------------------------------------------------------
SQL>select*fromuser_role_privs;
USERNAMEGRANTED_ROLEADMIN_OPTIONDEFAULT_ROLEOS_GRANTED
----------------------------------------------------------------------------------------------
LUNARCONNECTNOYESNO
LUNARRESOURCENOYESNO
PUBLICPLUSTRACENOYESNO
SQL>selectcount(*)fromv$fixed_table;
selectcount(*)fromv$fixed_table
ORA-00942:表或视图不存在
必需受权:
SQL>conn/@test1assysdba
已毗连。
SQL>grantselectonv_$fixed_tabletolunar;
受权乐成。
SQL>connlunar/lunar@test1
已毗连。
SQL>
失掉受权的一般用户仍旧只能会见V$开首的视图,而不克不及间接会见V_$开首的视图,
由于实践上V$视图是V_$视图的私有同义词(PUBLICSYNONYM)
要想会见V_$必需带上SYS.V_$,比方
SQL>selectcount(*)fromv$fixed_table;
COUNT(*)
----------
912
SQL>selectcount(*)fromv_$fixed_table;
selectcount(*)fromv_$fixed_table
ORA-00942:表或视图不存在
SQL>selectcount(*)fromsys.v_$fixed_table;
COUNT(*)
----------
912
SQL>
也能够授与用户SELECTanytable权限,如许这个用户就能够会见一切的V$视图了:
SQL>grantselectanytabletolunar;
受权乐成。
SQL>select*fromuser_role_privs;
USERNAMEGRANTED_ROLEADMIN_OPTIONDEFAULT_ROLEOS_GRANTED
----------------------------------------------------------------------------------------------
LUNARCONNECTNOYESNO
LUNARRESOURCENOYESNO
PUBLICPLUSTRACENOYESNO
SQL>select*fromuser_sys_privs;
USERNAMEPRIVILEGEADMIN_OPTION
----------------------------------------------------------------------------------
LUNARSELECTANYTABLENO
SQL>selectcount(*)fromv$fixed_table;
COUNT(*)
----------
912
SQL>select*fromv$fixed_tablewhererownum<2;
NAMEOBJECT_IDTYPETABLE_NUM
-------------------------------------------------------
X$KQFTA4294950912TABLE0
SQL>select*fromv_$fixed_tablewhererownum<2;
select*fromv_$fixed_tablewhererownum<2
ORA-00942:表或视图不存在
SQL>select*fromsys.v_$fixed_tablewhererownum<2;
NAMEOBJECT_IDTYPETABLE_NUM
-------------------------------------------------------
X$KQFTA4294950912TABLE0
SQL>
经由过程查询V$FIXED_TABLE视图,我们能够看到年夜部分V$视图和一些X$视图(另有一些ORACLE未公然的视图不在个中)。
那末这些V$视图又是有甚么构成的呢?
经由过程查询V$FIXED_VIEW_DEFINITION视图,能够看到这些V$视图的创立语句
SQL>conn/@test1assysdba
已毗连。
SQL>grantselectanytabletolunar;
受权乐成。
SQL>connlunar/lunar@test1
已毗连。
SQL>
SQL>setheadingoffechoofflong50000pages10000
SQL>select*fromv$fixed_view_definitionwhereview_name=V$FIXED_TABLE;
V$FIXED_TABLEselectNAME,OBJECT_ID,TYPE,TABLE_NUMfromGV$FIXED_TABLEwhereinst_id=USERENV(Instance)
SQL>
selectNAME,OBJECT_ID,TYPE,TABLE_NUM
fromGV$FIXED_TABLE
whereinst_id=USERENV(Instance)
那末这个GV$FIXED_TABLE视图的界说又是如何的呢?
SQL>select*fromv$fixed_view_definitionwhereview_name=GV$FIXED_TABLE;
GV$FIXED_TABLEselectinst_id,kqftanam,kqftaobj,TABLE,indxfromx$kqftaunionallselectinst_id,kqfvinam,kqfviobj,VIEW,65537fromx$kqfviunionallselectinst_id,kqfdtnam,kqfdtobj,TABLE,65537fromx$kqfdt
SQL>
selectinst_id,kqftanam,kqftaobj,TABLE,indxfromx$kqfta
unionall
selectinst_id,kqfvinam,kqfviobj,VIEW,65537fromx$kqfvi
unionall
selectinst_id,kqfdtnam,kqfdtobj,TABLE,65537fromx$kqfdt
如许我们就找到了创立一个V$视图的最低层的信息,即一个V$视图是由哪些X$表组成的。
要找究竟层X$表的索引信息,能够查询v$indexed_fixed_column:
SQL>descv$indexed_fixed_column
NameTypeNullableDefaultComments
--------------------------------------------------
TABLE_NAMEVARCHAR2(30)Y
INDEX_NUMBERNUMBERY
COLUMN_NAMEVARCHAR2(30)Y
COLUMN_POSITIONNUMBERY
SQL>
比方:
SQL>select*fromv$indexed_fixed_columnwheretable_name=X$KQFTA;
TABLE_NAMEINDEX_NUMBERCOLUMN_NAMECOLUMN_POSITION
---------------------------------------------------------------------------------------
X$KQFTA1ADDR0
X$KQFTA2INDX0
SQL>
一样平常来讲,V$视图和GV$视图的界说是一样的,只是GV$视图中包括的实例id的信息,经常使用于OPS大概RAC的体系中,也有多数几个V$视图和GV$视图的界说是有区分的,好比GV$PX_PROCESS和V$PX_PROCESS:
SQL>select*fromv$fixed_view_definitionwhereview_name=GV$PX_PROCESS;
GV$PX_PROCESSselecta.inst_id,a.kxfpdpnam,decode(bitand(a.kxfpdpflg,16),0,INUSE,AVAILABLE),b.pid,a.kxfpdpspid,c.sid,c.serial#fromx$kxfpdpa,V$PROCESSb,V$SESSIONcwherebitand(kxfpdpflg,8)!=0anda.kxfpdpspid=b.SPIDanda.kxfpdpspid=c.PROCESS(+)
SQL>
selecta.inst_id,a.kxfpdpnam,
decode(bitand(a.kxfpdpflg,16),0,INUSE,AVAILABLE),
b.pid,a.kxfpdpspid,c.sid,c.serial#
fromx$kxfpdpa,V$PROCESSb,V$SESSIONc
wherebitand(kxfpdpflg,8)!=0anda.kxfpdpspid=b.SPIDanda.kxfpdpspid=c.PROCESS(+)
SQL>select*fromv$fixed_view_definitionwhereview_name=V$PX_PROCESS;
V$PX_PROCESSselectSERVER_NAME,STATUS,PID,SPID,SID,SERIAL#fromGV$PX_PROCESSwhereinst_id=USERENV(Instance)
SQL>
selectSERVER_NAME,STATUS,PID,SPID,SID,SERIAL#
fromGV$PX_PROCESS
whereinst_id=USERENV(Instance)
2、数据字典的构成
怎样失掉一个数据字典表的界说呢?
SQL>descdba_views
NameTypeNullableDefaultComments
--------------------------------------------------------------------------------------------------------
OWNERVARCHAR2(30)Owneroftheview
VIEW_NAMEVARCHAR2(30)Nameoftheview
TEXT_LENGTHNUMBERYLengthoftheviewtext
TEXTLONGYViewtext
TYPE_TEXT_LENGTHNUMBERYLengthofthetypeclauseoftheobjectview
TYPE_TEXTVARCHAR2(4000)YTypeclauseoftheobjectview
OID_TEXT_LENGTHNUMBERYLengthoftheWITHOBJECTOIDclauseoftheobjectview
OID_TEXTVARCHAR2(4000)YWITHOBJECTOIDclauseoftheobjectview
VIEW_TYPE_OWNERVARCHAR2(30)YOwnerofthetypeoftheviewiftheviewisanobjectview
VIEW_TYPEVARCHAR2(30)YTypeoftheviewiftheviewisanobjectview
SUPERVIEW_NAMEVARCHAR2(30)YNameofthesuperview,ifviewisasubview
SQL>
SQL>setheadingoffechoofflong1000000000pages10000
SQL>selecttextfromdba_viewswhereview_name=DBA_USERS;
selectu.name,u.user#,u.password,
m.status,
decode(u.astatus,4,u.ltime,
5,u.ltime,
6,u.ltime,
8,u.ltime,
9,u.ltime,
10,u.ltime,to_date(NULL)),
decode(u.astatus,
1,u.exptime,
2,u.exptime,
5,u.exptime,
6,u.exptime,
9,u.exptime,
10,u.exptime,
decode(u.ptime,,to_date(NULL),
decode(pr.limit#,2147483647,to_date(NULL),
decode(pr.limit#,0,
decode(dp.limit#,2147483647,to_date(NULL),u.ptime+
dp.limit#/86400),
u.ptime+pr.limit#/86400)))),
dts.name,tts.name,u.ctime,p.name,u.defschclass,u.ext_username
fromsys.user$u,sys.ts$dts,sys.ts$tts,sys.profname$p,
sys.user_astatus_mapm,sys.profile$pr,sys.profile$dp
whereu.datats#=dts.ts#
andu.resource$=p.profile#
andu.tempts#=tts.ts#
andu.astatus=m.status#
andu.type#=1
andu.resource$=pr.profile#
anddp.profile#=0
anddp.type#=1
anddp.resource#=1
andpr.type#=1
andpr.resource#=1
SQL>
3、怎样查找用户自界说的某个表的界说?
在Oracle9i之前,可使用上面的办法:
SQL>selectsubstr(table_name,1,20)tabname,
2substr(column_name,1,20)column_name,
3rtrim(data_type)||(||data_length||)fromdba_tab_columns
4whereowner=&username
5/
TABNAMECOLUMN_NAMERTRIM(DATA_TYPE)||(||DATA_LE
----------------------------------------------------------------------------------------------------------------------------------------------------------------
BONUSENAMEVARCHAR2(10)
BONUSJOBVARCHAR2(9)
BONUSSALNUMBER(22)
BONUSCOMMNUMBER(22)
DEPTDEPTNONUMBER(22)
DEPTDNAMEVARCHAR2(14)
DEPTLOCVARCHAR2(13)
DUMMYDUMMYNUMBER(22)
EMPEMPNONUMBER(22)
EMPENAMEVARCHAR2(10)
EMPJOBVARCHAR2(9)
EMPMGRNUMBER(22)
EMPHIREDATEDATE(7)
EMPSALNUMBER(22)
EMPCOMMNUMBER(22)
EMPDEPTNONUMBER(22)
SALGRADEGRADENUMBER(22)
SALGRADELOSALNUMBER(22)
SALGRADEHISALNUMBER(22)
19rowsselected
SQL>
从Oracle9i入手下手,可使用dbms_metadata.get_ddl来找到工具的界说,比方:
SQL>@C:TEMPget_obj_sql.sql
SQL>setheadingoffechooffpages10000long90000
输出object_type的值:TABLE
输出object_name的值:EMP
输出object_owner的值:LUNAR
原值1:selectdbms_metadata.get_ddl(upper(&OBJECT_TYPE),upper(&OBJECT_NAME),upper(&OBJECT_O
WNER))fromdual
新值1:selectdbms_metadata.get_ddl(upper(TABLE),upper(EMP),upper(LUNAR))fromdual
CREATETABLE"LUNAR"."EMP"
("EMPNO"NUMBER(4,0)NOTNULLENABLE,
"ENAME"VARCHAR2(10),
"JOB"VARCHAR2(9),
"MGR"NUMBER(4,0),
"HIREDATE"DATE,
"SAL"NUMBER(7,2),
"COMM"NUMBER(7,2),
"DEPTNO"NUMBER(2,0)
)PCTFREE10PCTUSED40INITRANS1MAXTRANS255NOCOMPRESSLOGGING
STORAGE(INITIAL65536NEXT1048576MINEXTENTS1MAXEXTENTS2147483645
PCTINCREASE0FREELISTS1FREELISTGROUPS1BUFFER_POOLDEFAULT)
TABLESPACE"SYSTEM"
SQL>
注重,这个查询是必要一时表空间的,以是假如一时表空间不敷查询就会有成绩了:
SQL>@C:TEMPget_obj_sql.sql
SQL>setheadingoffechooffpages10000long90000
输出object_type的值:TABLE
输出object_name的值:DEPT
输出object_owner的值:LUNAR
原值1:selectdbms_metadata.get_ddl(upper(&OBJECT_TYPE),upper(&OBJECT_NAME),upper(&OBJECT_O
WNER))fromdual
新值1:selectdbms_metadata.get_ddl(upper(TABLE),upper(DEPT),upper(LUNAR))fromdual
ERROR:
ORA-25153:一时表空间为空
ORA-06512:在"SYS.DBMS_LOB",line424
ORA-06512:在"SYS.DBMS_METADATA",line557
ORA-06512:在"SYS.DBMS_METADATA",line1221
ORA-06512:在line1
未选定行
SQL>
SQL>SELECTNAMEFROMV$TEMPFILE;
未选定行
SQL>SELECTNAMEFROMV$TABLESPACE;
NAME
------------------------------
SYSTEM
UNDOTBS1
TEMP
INDX
USERS
SQL>ALTERTEMPORARYTABLESPACETEMPADDTEMPFILED:oracle92oradata est1TEMP01.DBFSIZE10M;
ALTERTEMPORARYTABLESPACETEMPADDTEMPFILED:oracle92oradata est1TEMP01.DBFSIZE10M
*
ERROR位于第1行:
ORA-00940:有效的ALTER命令
SQL>ALTERTABLESPACETEMPADDTEMPFILED:oracle92oradata est1TEMP01.DBFSIZE10M;
表空间已变动。
SQL>@C:TEMPget_obj_sql.sql
SQL>setheadingoffechooffpages10000long90000
输出object_type的值:TABLE
输出object_name的值:EMP
输出object_owner的值:LUNAR
原值1:selectdbms_metadata.get_ddl(upper(&OBJECT_TYPE),upper(&OBJECT_NAME),upper(&OBJECT_O
WNER))fromdual
新值1:selectdbms_metadata.get_ddl(upper(TABLE),upper(EMP),upper(LUNAR))fromdual
CREATETABLE"LUNAR"."EMP"
("EMPNO"NUMBER(4,0)NOTNULLENABLE,
"ENAME"VARCHAR2(10),
"JOB"VARCHAR2(9),
"MGR"NUMBER(4,0),
"HIREDATE"DATE,
"SAL"NUMBER(7,2),
"COMM"NUMBER(7,2),
"DEPTNO"NUMBER(2,0)
)PCTFREE10PCTUSED40INITRANS1MAXTRANS255NOCOMPRESSLOGGING
STORAGE(INITIAL65536NEXT1048576MINEXTENTS1MAXEXTENTS2147483645
PCTINCREASE0FREELISTS1FREELISTGROUPS1BUFFER_POOLDEFAULT)
TABLESPACE"SYSTEM"
SQL>
SQL>
dbms_metadata.get_ddl也能够用来查询其他工具的创立语句,利用办法以下;
selectdbms_metadata.get_ddl(工具范例,工具名,用户名)fromdual;
比方:
oracle@cs_db02:/arch1/lunar/tools>get_obj_sql.shprocedureaamisc
Connected.
CREATEORREPLACEPROCEDURE"MISC"."AA"is
begin
deletefromerror_tip;
endaa;
oracle@cs_db02:/arch1/lunar/tools>
支持多种存储引擎。 |
|