,TIPTOP,数据库管理(,Oracle,),(四),TIPTOP,事业部,课程大纲,表与索引,常见操作与相关数据字典,数据导出与导入,TIPTOP,工具脚本,Oracle,中的数据是怎样存放的,怎样对,TIPTOP,数据进行备份和恢复,TIPTOP,的多工厂数据是怎样存放的,课程简介,表、同义词,您现在的位置,数据库,环境(正式区、测试区),工厂(营运中心),业务数据,TIPTOP,Oracle,用户,表,系统数据,同义词,Oracle,表,数据库,数据库,数据库,表空间,数据库,段,数据库,分区,数据库,Oracle,块,数据库,数据文件,数据库,OS,块,逻辑结构,物理结构,表和索引都位于该逻辑层次,表的物理位置由,Oracle,自行管理,对用户透明,数据的存储方式,每个行以变长记录的形式存放在数据块中,其中的各个列根据定义时的顺序排列,每个行包括下面两个局部:,行首:存放行编号、相关的链接信息以及该行的锁定(lock)状态,行数据:该行中各个列的信息,每个列信息由13个字节的列长度定义及数据构成,行与行之间是紧密排列的,每个行的起始位置会记录于整个块首的分区表中,数据库块(,block,),行首,列长度,列数据,表操作,创立表,Oracle中推荐以VARCHAR2取代VARCHAR来存放字符串信息,这两种的类型的区别在于VARCHAR是跟随SQL标准定义,在各个不同的Oracle版本中可能有不同的定义,而VARCHAR2是由Oracle自己定义并保证其在各版本间的兼容性,在TIPTOP中标准的数据类型有以下几种:,NUMBER、CHAR、DATE、VARCHAR2、BLOB,SQLCREATE TABLE imx_file(,imx01 VARCHAR2(60),imx02 VARCHAR2(10),imx03 SMALLINT,imx04 DATE,imx05 NUMBER(6);,SQLCREATE TABLE imx_file(,imx01 VARCHAR2(60),imx02 VARCHAR2(10),imx03 SMALLINT,imx04 DATE,imx05 NUMBER(6);,表操作,使用现有数据来创立表,复制一个表,创立一个空表,从几个表中选取记录来创立,SQLCREATE TABLE AS SELECT,SQLCREATE TABLE AS SELECT,SQLCREATE TABLE AS SELECT,SQLCREATE TABLE imx_temp AS SELECT*FROM imx_file,SQLCREATE TABLE imx_temp AS,SELECT*FROM imx_ 1=0,SQLCREATE TABLE imx_temp AS,SELECT*FROM imx_ 1=0,SQLCREATE TABLE imx_temp AS,SELECT imx01,imd02 FROM imx_,WHERE imx01=imd01,SQLCREATE TABLE imx_temp AS,SELECT imx01,imd02 FROM imx_,WHERE imx01=imd01,表操作,删除表,截断表,截断表的结果是将表中数据全部删除,和使用,DELETE,语句的效果相同,两者的区别在与截断操作不记录,Redo Log,信息,所以更快,但操作无法恢复,所以在程序撰写过程中,,一般对于临时表使用截断语句,修改表名称,修改表名之后原索引实效,必须将其重建,SQLDROP TABLE imx_temp;,SQLDROP TABLE imx_temp;,SQLDROP TABLE imx_temp;,SQLTRUNCATE TABLE imx_temp;,SQLDROP TABLE imx_temp;,SQLRENAME imx_temp to imx_temp1;,表操作,查看表结构,SQLDROP TABLE imx_temp;,SQLdesc imx_file;,名称 是否为空,?,类型,-,IMX000 NOT NULL VARCHAR2(40),IMX00 VARCHAR2(40),IMX01 VARCHAR2(40),IMX02 VARCHAR2(40),IMX03 VARCHAR2(10),IMX04 VARCHAR2(10),IMX05 VARCHAR2(10),IMX06 VARCHAR2(40),IMX07 VARCHAR2(40),IMX08 VARCHAR2(40),IMX09 VARCHAR2(40),IMX10 VARCHAR2(40),名称 是否为空,?,类型,-,IMX000 NOT NULL VARCHAR2(40),IMX00 VARCHAR2(40),IMX01 VARCHAR2(40),IMX02 VARCHAR2(40),IMX03 VARCHAR2(10),IMX04 VARCHAR2(10),IMX05 VARCHAR2(10),IMX06 VARCHAR2(40),IMX07 VARCHAR2(40),IMX08 VARCHAR2(40),IMX09 VARCHAR2(40),IMX10 VARCHAR2(40),修改表结构,增加栏位,删除栏位,修改栏位数据类型,栏位更名,修改栏位,NOT NULL,约束,SQLDROP TABLE imx_temp;,SQLALTER TABLE imx_ imx11 varchar2(10);,SQLDROP TABLE imx_temp;,SQLALTER TABLE imx_ column imx11;,SQLDROP TABLE imx_temp;,SQLALTER TABLE imx_ imx11 varchar2(20);,SQLDROP TABLE imx_temp;,SQLALTER TABLE imx_ column imx1 to imx2;,SQLDROP TABLE imx_temp;,SQLALTER TABLE imx_temp modiy imx11 null/not null;,数据字典与动态性能视图,DBA_TABLES DBA_TAB_COLUMNS,ALL_TABLES ALL_TAB_COLUMNS,USER_TABLES USER_TAB_COLUMNS,DBA_TABLES DBA_TAB_COLUMNS DBA_OBJECTS,ALL_TABLES ALL_TAB_COLUMNS ALL_OBJECTS,USER_TABLES USER_TAB_COLUMNS USER_OBJECTS,DBA_XXX,SYSTEM,DS,DS1,DS2,USER_XXX,USER_XXX,USER_XXX,USER_XXX,ALL_XXX,TIPTOP,相关脚本,查询当前被锁定的表,解除对某个表的锁定:,SQLq_datafile,SQLq_locktable,Locked Object Tiptop User Proc Terminal SID SERIAL#MACHINE,-,DS1.OGB_FILE tiptop 28525 136 3727 ERP,DS1.OHA_FILE tiptop 28525 136 3727 ERP,DS1.OGA_FILE tiptop 3491 146 2543 ERP,DS1.OGA_FILE tiptop 3603 147 1906 ERP,DS1.OGB_FILE tiptop 3603 147 1906 ERP,DS1.OMA_FILE tiptop 3603 147 1906 ERP,Locked Object Tiptop User Proc Terminal SID SERIAL#MACHINE,-,DS1.OGB_FILE tiptop 28525 136 3727 ERP,DS1.OHA_FILE tiptop 28525 136 3727 ERP,DS1.OGA_FILE tiptop 3491 146 2543 ERP,DS1.OGA_FILE tiptop 3603 147 1906 ERP,DS1.OGB_FILE tiptop 3603 147 1906 ERP,DS1.OMA_FILE tiptop 3603 147 1906 ERP,SQLq_datafile,SQLalter system kill session,SID,SERIAL,;,TIPTOP,相关脚本,查询当前系统中的锁,SQLq_datafile,SQLq_lock,OS_USER PID ORL_USR OID LOCK_TYPE LOCK_HELD LOCK_REQUEST STATUS OWNER OBJ_NAME,-,tiptop 3603 DS1 147 Transaction Exclusive None Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 Transaction None Exclusive Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 Transaction Exclusive None Blocking DS1 OGA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OGA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OGA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OGA_FILE,tiptop 3603 DS1 147 Transaction None Exclusive Not Blocking DS1 OGA_FILE,tiptop 3491 DS1 146 Transaction Exclusive None Blocking DS1 OGA_FILE,OS_USER PID ORL_USR OID LOCK_TYPE LOCK_HELD LOCK_REQUEST STATUS OWNER OBJ_NAME,-,tiptop 3603 DS1 147 Transaction Exclusive None Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 Transaction None Exclusive Not Blocking DS1 OMA_FILE,tiptop 3603 DS1 147 Transaction Exclusive None Blocking DS1 OGA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not Blocking DS1 OGA_FILE,tiptop 3603 DS1 147 DML Row-X(SX)None Not