oracle基本sql语句
上面是常用的导出,对于压缩,既用winzip把dmp文件可以很好的压缩。
也可以在上面命令后面 加上 compress=y 来实现。数据的导入
1 将D:daochu.dmp 中的数据导入 TEST数据库中。
?? imp?system/manager@TEST?file=d:daochu.dmp
?? imp?aichannel/aichannel@HUST?full=y file=d:datanewsmgnt.dmp ignore=y
?? 上面可能有点问题,因为有的表已经存在,然后它就报错,对该表就不进行导入。
?? 在后面加上 ignore=y 就可以了。
2 将d:daochu.dmp中的表table1 导入
imp?system/manager@TEST?file=d:daochu.dmp tables=(table1)基本上上面的导入导出够用了。不少情况要先是将表彻底删除,然后导入。注意:
操作者要有足够的权限,权限不够它会提示。
数据库时可以连上的。可以用tnsping TEST 来获得数据库TEST能否连上。附录一:
给用户增加导入数据权限的操作
第一,启动sql*puls
第二,以system/manager登陆
第三,create user 用户名 IDENTIFIED BY 密码 (如果已经创建过用户,这步可以省略)
第四,GRANT CREATE USER,DROP USER,ALTER USER ,CREATE ANY VIEW ,
?? DROP ANY VIEW,EXP_FULL_DATABASE,IMP_FULL_DATABASE,
????? DBA,CONNECT,RESOURCE,CREATE SESSION TO 用户名字
第五, 运行-cmd-进入dmp文件所在的目录,
????? imp userid=system/manager full=y file=*.dmp
????? 或者 imp userid=system/manager full=y file=filename.dmp执行示例:
F:WorkOracle_Databackup>imp userid=test/test full=y file=inner_notify.dmp屏幕显示
Import: Release 8.1.7.0.0 - Production on 星期四 2月 16 16:50:05 2006
(c) Copyright 2000 Oracle Corporation. All rights reserved.连接到: Oracle8i Enterprise Edition Release 8.1.7.0.0 - Production
With the Partitioning option
JServer Release 8.1.7.0.0 - Production经由常规路径导出由EXPORT:V08.01.07创建的文件
已经完成ZHS16GBK字符集和ZHS16GBK NCHAR 字符集中的导入
导出服务器使用UTF8 NCHAR 字符集 (可能的ncharset转换)
. 正在将AICHANNEL的对象导入到 AICHANNEL
. . 正在导入表????????????????? "INNER_NOTIFY"????????? 4行被导入
准备启用约束条件...
成功终止导入,但出现警告。
附录二:
Oracle 不允许直接改变表的拥有者, 利用Export/Import可以达到这一目的.
先建立import9.par,
然后,使用时命令如下:imp parfile=/filepath/import9.par
例 import9.par 内容如下:
??????? FROMUSER=TGPMS???????
??????? TOUSER=TGPMS2???? (注:把表的拥有者由FROMUSER改为TOUSER,FROMUSER和TOUSER的用户可以不同)??????????
??????? ROWS=Y
??????? INDEXES=Y
??????? GRANTS=Y
??????? CONSTRAINTS=Y
??????? BUFFER=409600
??????? file==/backup/ctgpc_20030623.dmp
??????? log==/backup/import_20030623.log
创建用户
-- Create the user?
create user JXTELE_HOMS
identified by "123456"
default tablespace HOMS
temporary tablespace TEMP
profile DEFAULT;
-- Grant/Revoke role privileges?
grant connect to JXTELE_HOMS with admin option;
grant dba to JXTELE_HOMS with admin option;
grant resource to JXTELE_HOMS with admin option;
-- Grant/Revoke system privileges?
grant unlimited tablespace to JXTELE_HOMS with admin option;
创建视图
create or replace view inpass_encape_byid as
select p.*,e.ESCAPECODE???? ,e.ESCAPE_NAME??? ,e.ESCAPE_SEX???? ,e.ESCAPE_BIRTHDAY,e.ESCAPE_IDCARD ,e.ESCAPE_AREA??? ,
e.ESCAPE_ADDRESS ,e.REASON???????? ,e.WATCHTIME????? ,
e.WATCHUNIT????? ,e.SIGN?????????? ,e.AGE??????????? ,e.CALLPHONE????? ,e.CALLTELEPHONE ,e.WATCHUNITCODE ,h.hotelname?
from in_passenger p join escape e on p.cardcode=e.escape_idcard join hotel h on p.hotelcode=h.hotelcode;
create or replace view in_out_passstatic as
select code,name,count(pcode) cnt,intime,decode(a.roomcount,null,'0',a.roomcount) roomcount
from (select h.hotelcode code,h.hotelname name,substr(i.in_datetime,0,8) intime,i.in_passengercode pcode,h.roomcount roomcount
from IN_Passenger i right join Hotel h on i.hotelcode=h.hotelcode?????
group by h.HotelCode,substr(i.in_datetime,0,8),h.hotelname,i.in_passengercode,h.roomcount
?? union select t.hotelcode code,t.hotelname name,substr(p.in_datetime,0,8) intime,p.out_passengercode pcode,t.roomcount roomcount
??? from Out_Passenger p right join Hotel t?? on?? p.hotelcode=t.hotelcode???
???? group by t.HotelCode,substr(p.in_datetime,0,8),t.hotelname,p.out_passengercode,t.roomcount ) a?
???? group by a.code,a.intime,a.name,a.roomcount order by a.code;
create or replace view in_passstatic as
select code,name,count(pcode) cnt,intime,decode(a.roomcount,null,'0',a.roomcount) roomcount?
from (select h.hotelcode code,h.hotelname name,substr(i.in_datetime,0,8) intime,i.in_passengercode pcode,h.roomcount
from IN_Passenger i right join Hotel h on i.hotelcode=h.hotelcode?
?? group by h.HotelCode,substr(i.in_datetime,0,8),h.hotelname,i.in_passengercode,h.roomcount) a
??? group by a.code,a.intime,a.name,a.roomcount order by a.code;
create or replace view out_passstatic as
select code,name,count(pcode) cnt,intime,decode(a.roomcount,null,'0',a.roomcount) roomcount?
from (select t.hotelcode code,t.hotelname name,substr(p.in_datetime,0,8) intime,p.out_passengercode pcode,t.roomcount?
from Out_Passenger p right join Hotel t?? on?? p.hotelcode=t.hotelcode???
group by t.HotelCode,substr(p.in_datetime,0,8),t.hotelname,p.out_passengercode,t.roomcount ) a?
group by a.code,a.intime,a.name,a.roomcount order by a.code;