慢慢积累,就会丰富的:
sqlplus /nolog //实例没有打开的情况下用sqlplus登录
connect sys/密码 as sysdba
startup //首先启动实例,打开控制文件,再打开数据文件
shutdown immediate //正常关闭
sqlplus sys/密码 as sysdba //实例打开的情况下
alter user scott account unlock //scott用户解锁
conn scott/tiger //scott用户登录
如果SYS,SYSTEM用户的密码都忘记或是丢失。
可以使用ORAPWD.EXE 工具修改密码。
开始菜单->运行->输入‘CMD’,打开命令提示符窗口,输入如下命令:
orapwd file=D:/oracle/product/10.2.0/db_1/database/pwdctcsys.ora
password=newpass
这个命令重新生成了数据库的密码文件。密码文件的位置在ORACLE_HOME目录下
的/database目录下。
这个密码是修改sys用户的密码。除sys和system其他用户的密码不会改变。
任意密码可以登录sys/password as sysdba :%ORACLE_HOME%/network/admin/sqlnet.ora中
SQLNET.AUTHENTICATION_SERVICES= (NONE) --> SQLNET.AUTHENTICATION_SERVICES= (NTS)
SELECT host_name, instance_name, version FROM v$instance;//查看实例名
//查询当前用户
show user;
数据字典表:user_tables
desc user_tables;
select table_name from user_tables;//当前用户有那些表
desc user_views;
select view_name from user_views;
desc user_constraints;
select constraint_name from user_constraints;//当前用户有那些约束
select constraint_name, table_name from user_constraints;//当前用户约束加在哪张表上
desc dictionary;
select table_name from dictionary;//有哪些数据字典表
select tablespace_name from USER_TABLESPACES;//查看用户属于那些表空间
查看用户和默认表空间的关系。
select username,default_tablespace from dba_users;
select * from user_objects;//查看当前用户的所有对象(table,index,procedure等)的信息
select text from user_source where name = 'yourpackagename ';-- sp,package //查看oracle中的存储过程、包、触发器都有那些
触发器:
select trigger_name,trigger_type,table_owner,table_name,status from user_triggers;
/*====================创建表空间=============================*/
create tablespace GEOBANK_ATTACH
datafile 'd:/oracle/oradata/GeoBank_Attach'
size 200M
autoextend on
next 5M
maxsize UNLIMITED;
create tablespace GEOBANK_CATALOG
datafile
'd:/oracle/oradata/GeoBank_Catalog'
size 20M
autoextend on
next 1M
maxsize UNLIMITED;
create tablespace GEOBANK_FILE
datafile
'd:/oracle/oradata/GeoBank_File'
size 200M
autoextend on
next 5M
maxsize UNLIMITED;
create tablespace GEOBANK_MAP
datafile
'd:/oracle/oradata/GeoBank_Map'
size 100M
autoextend on
next 1M
maxsize UNLIMITED;
create tablespace GEOBANK_META
datafile
'd:/oracle/oradata/GeoBank_Meta'
size 50M
autoextend on
next 1M
maxsize UNLIMITED;
create tablespace GEOBANK_RIGHT
datafile
'd:/oracle/oradata/GeoBank_Right'
size 20M
autoextend on
next 1M
maxsize UNLIMITED;
create tablespace GEOBANK_USER
datafile
'd:/oracle/oradata/GeoBank_User'
size 10M
autoextend on
next 1M
maxsize UNLIMITED;
/*========创建用户,对用户授权====================*/
CREATE USER "GEOBANK4" PROFILE "DEFAULT"
IDENTIFIED BY "GEOBANK4" DEFAULT TABLESPACE "GEOBANK_META"
ACCOUNT UNLOCK;
GRANT "CONNECT" TO "GEOBANK4";
GRANT "DBA" TO "GEOBANK4";
/*=================导出数据===================*/
exp username/password@服务名全称/实例名 full=y file=c:/temp/xxx.dmp
/*=================导入数据===================*/
执行imp命令导入数据 示例如下
导入数据需要授予用户dba权限: grant dba to user01;
导入完成后应取消用户的dba权限: revoke dba from user01;
imp GEOBANK4/GEOBANK4@GEOBANK file=d:/geobank20090319_二级站点正式库.dmp full=y
数据导出:
1 将数据库TEST完全导出,用户名system 密码manager 导出到D:/daochu.dmp中
exp system/manager@TEST file=d:/daochu.dmp full=y
2 将数据库中system用户与sys用户的表导出
exp system/manager@TEST file=d:/daochu.dmp owner=(system,sys)
3 将数据库中的表table1 、table2导出
exp system/manager@TEST file=d:/daochu.dmp tables=(table1,table2)
4 将数据库中的表table1中的字段filed1以"00"打头的数据导出
exp system/manager@TEST file=d:/daochu.dmp tables=(table1) query=/" where filed1 like '00%'/"
上面是常用的导出,对于压缩我不太在意,用winzip把dmp文件可以很好的压缩。不过在上面命令后面 加上 compress=y 就可以了
数据的导入
1 将D:/daochu.dmp 中的数据导入 TEST数据库中。
imp system/manager@TEST file=d:/daochu.dmp
上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
在后面加上 ignore=y 就可以了。
2 将d:/daochu.dmp中的表table1 导入
imp system/manager@TEST file=d:/daochu.dmp tables=(table1)