Oracle中常用SQL语句 下载本文

开启监听:cmd lsnrctl start 查看状态:lsnrctl status

更改表空间名称:

alter tablespace 表名 rename to 表名1;

修改用户密码:

alter user sys identified by 新密码;

---------------------创建数据文件----------------------------------

create tablespace abc_data datafile 'D:\\Data\\abc_data.dbf' size 100m AUTOEXTEND ON NEXT 10m maxsize unlimited;

---------------------创建临时数据文件---------------------------------- create temporary tablespace abc_TEMP tempfile 'D:\\Data\\abc_TEMP.dbf' size 100m AUTOEXTEND ON NEXT 10m maxsize unlimited;

--------------------创造用户-------------------------------------

create user abc identified by 123 default tablespace abc_DATA temporary tablespace abc_TEMP;

--------------------grant权限------------------------------------- grant connect,resource,dba to abc;

--------------------导入数据------------------------------------- imp abc/123@orcl123 file=D:\\XX项目\\XXX.dmp full=y; --------------------导出数据-------------------------------------

开始->运行->输入“cmd”->输入exp user/password@IP地址:1521/数据库实例 file=文件所在目录 (

exp

user/password@192.168.1.xxx:1521/orcl

file=E:\\xxx\\xxx\\xxx.dmp)

exp用户名/密码@ora219 file=e:\\命名.dmp

1、 查询不在另一张表的记录

select a.* from a where bid not in (select distinct bid from b) 2、 被修改值由另一张表运算而来

(1)update a, b set a.nm1=b.nm2,a.cd1=b.cd2 where a.id1=b.id2;

(2)update a set a.nm1=(select b.nm2 from b where b.id2=a.id1) where [not] exists(select 1 from b where b.id2=a.id1); (1个字段) (3)update a set (a.nm1,a.cd1)=(select b.nm2,b.cd2 from b where

b.id2=a.id1) where exists (select 1 from b where b.id2=a.id1); (2个或以上字段)

3、 两张一样的表a , b ,只有sm字段值不一样(都只有一部分),现将两表

合并(将b表中sm的值赋给a表)

update a, b set a.sm=b.sm

where a.xh =b.xh and b.sm is not null and a.sm is null 4、 通过已有表中的数据添加记录

insert into A(aid,a,b,c,d,e)

SELECT bid+100000, a,b,c,d,e FROM B WHERE ….. 5、 替换

select * from T where dh like '%-0%' and 年份 is null ;

update T set dh=replace(dh,'-0','-') where dh like '%-0%' and 年份 is null; 6、 查找重复

(1)select * from A where aId in (select aId from A group by aId having count

(aId) > 1)

(2)SELECT a1.* FROM A a1,A a2 WHERE a1.id<>a2.id (3)删除重复记录

delete from A where aId in (select aId from A group by aId having count(aId)>1)