oracle数据库常用操作命令
查看Oracle的版本:
select * from product_component_version;
查看当前用户所具有的权限:
SELECT * FROM DBA_SYS_PRIVS WHERE GRANTEE = 'KNMY';
或
select * from user_sys_privs;
用户的登录:
[username/password] [@server] [as sysdba/sysoper] 举例:sys/pass as sysdba
用户的切换:
[connect] [username/password] [@server] [as sysdba/sysoper] 举例: connect system/pass
显示当前登陆的用户:
show user
显示数据字典中的字段:
desc dba_users
desc table_spaces
desc user_tablespaces
desc user_users
desc dba_data_files
desc dba_temp_files
desc dba_role_privs
创建用户且指定表空间:
CREATE USER username IDENTIFIED BY password
DEFAULT TABLESPACE TEST_DATA
TEMPORARY TABLESPACE TEST_TEMP;
删除用户:
drop user ×× cascade;
给用户赋予权限:
GRANT
CREATE SESSION, CREATE ANY TABLE, CREATE ANY VIEW ,CREATE ANY INDEX,
CREATE ANY PROCEDURE,ALTER ANY TABLE, ALTER ANY PROCEDURE,
DROP ANY TABLE, DROP ANY VIEW, DROP ANY INDEX, DROP ANY PROCEDURE,
SELECT ANY TABLE, INSERT ANY TABLE, UPDATE ANY TABLE, DELETE ANY TABLE
TO username;
将role这个角色授予username:
GRANT role TO username;
设置用户的默认或者临时表空间:
ALTER USER username DEFAULT|TEMPORARY TABLESPACE tablespace_name
创建表空间:
CREATE [TEMPORARY] TABLESPACE tablespace_name TEMPFILE|DATAFILE 'xx.dbf' SIZE xx;
举例:
创建临时表空间:
CREATE TEMPORARY TABLESPACE test_temp
TEMPFILE 'D:\oracle\product\10.1.0\oradata\orcl\test_temp01.dbf'
SIZE 32M
AUTOEXTEND ON
NEXT 32M MAXSIZE 2048M
EXTENT MANAGEMENT LOCAL;
创建用户表空间:
CREATE TABLESPACE test_data
LOGGING
DATAFILE 'D:\ORACLE\PRODUCT\10.1.0\ORADATA\ORCL\TEST_DATA01.DBF'
SIZE 32M
AUTOEXTEND ON
NEXT 32M MAXSIZE 2048M
EXTENT MANAGEMENT LOCAL;
修改表空间的状态:
设置表空间的联机或者脱机状态:
ALTER TABLESPACE tablespace_name ONLINE|OFFLINE
设置表空间只读或者可读写状态:
ALTER TABLESPACE tablespace_name READ ONLY|READ WRITE
修改表空间的数据文件:
增加数据文件:
ALTER TABLESPACE tablespace_name ADD DATAFILE 'xx.dbf' SIZE xx
删除数据文件:
ALTER TABLESPACE tablespace_name DROP DATAFILE 'xx.dbf'
删除表空间:
DROP TABLESPACE tablespace_name [INCLUDING CONTENTS]
查看是否为CDB的数据库:
select * from v$database; 若CDB字段为YES,则是。