My Oracle Cook Book

My Oracle Cook Book

My Oracle Cook Book-来自oralce菜鸟的学习笔记

准备

用到的是oracle自带的用户和表
用户为scott/tiger
步骤是:连接数据库
-> sqlplus scott/tiger
Connected to Oracle Database 10g Enterprise Edition Release 10.1.0.2.0
Connected as scott.

初始认证用户

如果scott用户没有链接到数据库,
通过数据库认证查看用户的帐号状态,有可能是scott用户的状态处于EXPIRED & LOCKED

1-1   显示所有用户的帐号状态

以sysdba用户登录:
->sqlplus / as sysdba
查看所有用户的帐号状态查找的表为dba_users(视图);
SQL> desc dba_users;
Name                        Type           Nullable Default Comments                                
--------------------------- -------------- -------- ------- ---------------------------------------
USERNAME                    VARCHAR2(30)                    Name of the user                        
USER_ID                     NUMBER                          ID number of the user                   
PASSWORD                    VARCHAR2(30)   Y                Encrypted password                      
ACCOUNT_STATUS              VARCHAR2(32)                                                            
LOCK_DATE                   DATE           Y                                                        
EXPIRY_DATE                 DATE           Y                                                        
DEFAULT_TABLESPACE          VARCHAR2(30)                    Default tablespace for data             
TEMPORARY_TABLESPACE        VARCHAR2(30)                    Default tablespace for temporary tables
CREATED                     DATE                            User creation date                      
PROFILE                     VARCHAR2(30)                    User resource profile name              
INITIAL_RSRC_CONSUMER_GROUP VARCHAR2(30)   Y                User's initial consumer group           
EXTERNAL_NAME               VARCHAR2(4000) Y                User external name                      

(需要的表字段用红色标识)
SQL> select username,account_status from dba_users where username like 'S%';
 
USERNAME                       ACCOUNT_STATUS
------------------------------ --------------------------------
SYSMAN                         OPEN
SYS                            OPEN
SYSTEM                         OPEN
SI_INFORMTN_SCHEMA             EXPIRED & LOCKED
SCOTT                      EXPIRED & LOCKED
SH                             EXPIRED & LOCKED
注意scott用户的account_status状态
expired意思是用户的密码过期了。
Locked意思是用户帐号已经锁定

1.2 解锁用户和处理用户密码过期

SQL> alter user scott identified by tiger account unlock;
 
User altered
 
SQL> select username,account_status from dba_users where username like 'S%';

 
USERNAME                       ACCOUNT_STATUS
------------------------------ --------------------------------
SCOTT                          OPEN
SYSMAN                         OPEN
SYS                            OPEN
SYSTEM                         OPEN
SI_INFORMTN_SCHEMA             EXPIRED & LOCKED
SH                             EXPIRED & LOCKED
 
6 rows selected
注意scott状态已经打开
语句alter user scott identified by tiger account unlock;其中identified by tiger更新了密码,account unlock 解锁了scott用户
注意状态为OPEN状态
以scott用户登录
SQL> conn scott/tiger
Connected to Oracle Database 10g Enterprise Edition Release 10.1.0.2.0
Connected as scott


1.3查看用户下的表(user_tables视图)

SQL> desc user_tables;
Name                      Type         Nullable Default Comments                                                                                   
------------------------- ------------ -------- ------- ------------------------------------------------------------------------------------------
TABLE_NAME                VARCHAR2(30)                  Name of the table                                                                          
TABLESPACE_NAME           VARCHAR2(30) Y                Name of the tablespace containing the table                                                
CLUSTER_NAME              VARCHAR2(30) Y                Name of the cluster, if any, to which the table belongs                                    
IOT_NAME                  VARCHAR2(30) Y                Name of the index-only table, if any, to which the overflow or mapping table entry belongs
PCT_FREE                  NUMBER       Y                Minimum percentage of free space in a block                                                
PCT_USED                  NUMBER       Y                Minimum percentage of used space in a block                                                
INI_TRANS                 NUMBER       Y                Initial number of transactions                                                             
MAX_TRANS                 NUMBER       Y                Maximum number of transactions                                                             
INITIAL_EXTENT            NUMBER       Y                Size of the initial extent in bytes                                                        
NEXT_EXTENT               NUMBER       Y                Size of secondary extents in bytes                                                         
MIN_EXTENTS               NUMBER       Y                Minimum number of extents allowed in the segment                                           
MAX_EXTENTS               NUMBER       Y                Maximum number of extents allowed in the segment                                           
PCT_INCREASE              NUMBER       Y                Percentage increase in extent size                                                         
FREELISTS                 NUMBER       Y                Number of process freelists allocated in this segment                                      
FREELIST_GROUPS           NUMBER       Y                Number of freelist groups allocated in this segment                                        
LOGGING                   VARCHAR2(3)  Y                Logging attribute                                                                          
BACKED_UP                 VARCHAR2(1)  Y                Has table been backed up since last modification?                                          
NUM_ROWS                  NUMBER       Y                The number of rows in the table                                                            
BLOCKS                    NUMBER       Y                The number of used blocks in the table                                                     
EMPTY_BLOCKS              NUMBER       Y                The number of empty (never used) blocks in the table                                       
AVG_SPACE                 NUMBER       Y                The average available free space in the table                                              
CHAIN_CNT                 NUMBER       Y                The number of chained rows in the table                                                    
AVG_ROW_LEN               NUMBER       Y                The average row length, including row overhead                                             
AVG_SPACE_FREELIST_BLOCKS NUMBER       Y                The average freespace of all blocks on a freelist                                          
NUM_FREELIST_BLOCKS       NUMBER       Y                The number of blocks on the freelist                                                       
DEGREE                    VARCHAR2(10) Y                The number of threads per instance for scanning the table                                  
INSTANCES                 VARCHAR2(10) Y                The number of instances across which the table is to be scanned                            
CACHE                     VARCHAR2(5)  Y                Whether the table is to be cached in the buffer cache                                      
TABLE_LOCK                VARCHAR2(8)  Y                Whether table locking is enabled or disabled                                               
SAMPLE_SIZE               NUMBER       Y                The sample size used in analyzing this table                                               
LAST_ANALYZED             DATE         Y                The date of the most recent time this table was analyzed                                   
PARTITIONED               VARCHAR2(3)  Y                Is this table partitioned? YES or NO                                                       
IOT_TYPE                  VARCHAR2(12) Y                If index-only table, then IOT_TYPE is IOT or IOT_OVERFLOW or IOT_MAPPING else NULL         
TEMPORARY                 VARCHAR2(1)  Y                Can the current session only see data that it place in this object itself?                 
SECONDARY                 VARCHAR2(1)  Y                Is this table object created as part of icreate for domain indexes?                        
NESTED                    VARCHAR2(3)  Y                Is the table a nested table?                                                               
BUFFER_POOL               VARCHAR2(7)  Y                The default buffer pool to be used for table blocks                                        
ROW_MOVEMENT              VARCHAR2(8)  Y                Whether partitioned row movement is enabled or disabled                                    
GLOBAL_STATS              VARCHAR2(3)  Y                Are the statistics calculated without merging underlying partitions?                       
USER_STATS                VARCHAR2(3)  Y                Were the statistics entered directly by the user?                                          
DURATION                  VARCHAR2(15) Y                If temporary table, then duration is sys$session or sys$transaction else NULL              
SKIP_CORRUPT              VARCHAR2(8)  Y                Whether skip corrupt blocks is enabled or disabled                                         
MONITORING                VARCHAR2(3)  Y                Should we keep track of the amount of modification?                                        
CLUSTER_OWNER             VARCHAR2(30) Y                Owner of the cluster, if any, to which the table belongs                                   
DEPENDENCIES              VARCHAR2(8)  Y                Should we keep track of row level dependencies?                                            
COMPRESSION               VARCHAR2(8)  Y                Whether table compression is enabled or not                                                
DROPPED                   VARCHAR2(3)  Y                Whether table is dropped and is in Recycle Bin                                             
 
SQL> select table_name,tablespace_name from user_tables;

 
TABLE_NAME                     TABLESPACE_NAME
------------------------------ ------------------------------
SALGRADE                       USERS
BONUS                          USERS
EMP                            USERS
DEPT                           USERS

例子中主要适用EMP,DEPT俩个表

准备结束。下一节开始围绕该表介绍我的orcle SQL菜鸟笔记

你可能感兴趣的:(My Oracle Cook Book)