《!!Oracle数据库部分SQL语句.docx》由会员分享,可在线阅读,更多相关《!!Oracle数据库部分SQL语句.docx(5页珍藏版)》请在三一文库上搜索。
1、!Oracle数据库部分SQL语句用户解锁:ALTER USER username ACCOUNT UNLOCK;设置账户口令:ALTER USER username IDENTIFIED BY password;创建用户:create user username IDENTIFIED BY password;赋予权限(connect,resource,dba三个权限):Grant connect,resource,dba to username;查询用户:select*from all_users;删除用户:Drop user XXXX cascade;创建表空间(表空间名为test):Cr
2、eate tablespace test datafileD:test.orasize1000m;Create user test identified by test default tablespace test quota500m on users;Grant all privileges to test;删除表空间:可以先将其offlinealter tablespace xx offline;将磁盘上的数据文件一同删除drop tablespace xxx including contents and datafiles;删除用户:drop user xxx;如果用户的schema中
3、有objects,需要加cascade参数,即drop user xxx cascade;数据库导入/导出:一).导出1.exp方式:(1).将数据库TEST完全导出,用户名system密码manager导出到D:daochu.dmp中:exp system/managerTEST file=d:daochu.dmp(2).将数据库中system用户与sys用户的表导出exp system/managerTESTfile=d:daochu.dmp owner=(system,sys)(3).将数据库中的表inner_notify、notify_staff_relat导出exp aichanne
4、l/aichannelTESTDB2 file=d:datanewsmgnt.dmp tables=inner_notify,notify_staff_relat)(4).将数据库中的表table1中的字段filed1以00打头的数据导出expsystem/managerTEST file=d:daochu.dmp tables=(table1)query=where filed1like00%2.expdp方式:(1).创建逻辑目录,该命令不会在操作系统创建真正的目录,最好以system等管理员创建。create directory dpdata1asd:testdump;(2).查看管理理
5、员目录(同时查看操作系统是否存在,因为Oracle并不关心该目录是否存在,如果不存在,则出错)select*from dba_directories;(3).给scott用户赋予在指定目录的操作权限,最好以system等管理员赋予。grant read,write on directory dpdata1to scott;(4).导出数据1)按用户导expdp scott/tigerorcl DIRECTORY=dpdata1schemas=scott dumpfile=expdp.dmp;2)并行进程parallelexpdp scott/tigerorcl directory=dpdata
6、1dumpfile=scott3.dmp parallel=40job_name=scott33)按表名导expdp scott/tigerorcl TABLES=emp,dept dumpfile=expdp.dmp DIRECTORY=dpdata1;4)按查询条件导expdp scott/tigerorcl directory=dpdata1dumpfile=expdp.dmp Tables=empquery=WHERE deptno=20;5)按表空间导expdp system/manager DIRECTORY=dpdata1DUMPFILE=tablespace.dmp TABLE
7、SPACES=temp,example;6)导整个数据库expdp system/manager DIRECTORY=dpdata1DUMPFILE=full.dmp FULL=y;五、还原数据1)导到指定用户下impdp scott/tiger DIRECTORY=dpdata1DUMPFILE=expdp.dmp SCHEMAS=scott;2)改变表的ownerimpdp system/manager DIRECTORY=dpdata1DUMPFILE=expdp.dmp TABLES=scott.dept REMAP_SCHEMA=scott:system;3)导入表空间impdp s
8、ystem/manager DIRECTORY=dpdata1DUMPFILE=tablespace.dmp TABLESPACES=example;4)导入数据库impdb system/manager DIRECTORY=dump_dir DUMPFILE=full.dmp FULL=y;5)追加数据impdp system/manager DIRECTORY=dpdata1DUMPFILE=expdp.dmp SCHEMAS=system TABLE_EXISTS_ACTION查看sga_target大小:Show parameter sga查看pga_aggregate_target大小:Show parameter pga