关于oracle数据库的一些基本操作
2015-06-25 16:26
579 查看
在编程中,我们经常会使用各种数据库,比较常用的有oracle,MySQL,SqlServer等,我最近在使用oracle数据库,下面总结一些oracle数据库中经常使用的一些基本操作,分享
给大家。
1,在oracle中如何创建表空间以及创建用户和对用户授权
oracle不同于其他数据库,我们在创建表或者用户时,必须为其创建一个表空间,只有在表空间中才可以对我们的对象进行操作
2、几个简单的基本的sql语句
oracle中的语句和其他数据库SQL语句基本差不多,用法也差不多
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
子查询(表名1:a 表名2:b)
select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)
外连接查询(表名1:a 表名2:b)
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
in 的使用方法
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)
between的用法,between限制查询数据范围时包括了边界值,not between不包括
select * from table1 where time between time1 and time2
select a,b,c, from table1 where a not between 数值1 and 数值2
选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
以上就是我在学习时,总结在oracle数据库中一些基本操作,当然学习是相互积累的,如果有什么不对地方的希望大家及时指出。
给大家。
1,在oracle中如何创建表空间以及创建用户和对用户授权
oracle不同于其他数据库,我们在创建表或者用户时,必须为其创建一个表空间,只有在表空间中才可以对我们的对象进行操作
--创建表空间 create tablespace test_ts datafile 'F:/app/wmj3/oradata/orcl/test_ts.dbf' --该路径必须为本机上的真实路径 size 50m autoextend on next 50m extent management local; --在刚才创建的表空间下 创建用户名为 test_ts_user 登陆密码为123456 的用户 create user test_ts_user identified by "123456" default tablespace test_ts; --给用户授权,权限包括连接数据库,读写的一些基本操作。当然还有其他的一些不常用的操作,如果有需要可以加上去 grant connect, resource, create view to test_ts_user; --创建表 create table T_DEMO_INFO ( OBJECTID VARCHAR2(32) not null, NAME VARCHAR2(500), CODE VARCHAR2(4) ); --添加备注 comment on table T_DEMO_INFO is '企业办事项'; comment on column T_DEMO_INFO.OBJECTID is '主键ID'; comment on column T_DEMO_INFO.NAME is '姓名'; comment on column T_DEMO_INFO.CODE is '编号'; --为表创建主键,外键等约束关系 add constraint PK_UUID primary key (OBJECTID); --删除用户 drop user test_ts_user; --删除表空间 DROP TABLESPACE test_ts INCLUDING CONTENTS;
2、几个简单的基本的sql语句
oracle中的语句和其他数据库SQL语句基本差不多,用法也差不多
选择:select * from table1 where 范围
插入:insert into table1(field1,field2) values(value1,value2)
删除:delete from table1 where 范围
更新:update table1 set field1=value1 where 范围
查找:select * from table1 where field1 like ’%value1%’
排序:select * from table1 order by field1,field2 [desc]
总数:select count as totalcount from table1
求和:select sum(field1) as sumvalue from table1
平均:select avg(field1) as avgvalue from table1
最大:select max(field1) as maxvalue from table1
最小:select min(field1) as minvalue from table1
子查询(表名1:a 表名2:b)
select a,b,c from a where a IN (select d from b ) 或者: select a,b,c from a where a IN (1,2,3)
外连接查询(表名1:a 表名2:b)
select a.a, a.b, a.c, b.c, b.d, b.f from a LEFT OUT JOIN b ON a.a = b.c
in 的使用方法
select * from table1 where a [not] in (‘值1’,’值2’,’值4’,’值6’)
between的用法,between限制查询数据范围时包括了边界值,not between不包括
select * from table1 where time between time1 and time2
select a,b,c, from table1 where a not between 数值1 and 数值2
选择从10到15的记录
select top 5 * from (select top 15 * from table order by id asc) table_别名 order by id desc
以上就是我在学习时,总结在oracle数据库中一些基本操作,当然学习是相互积累的,如果有什么不对地方的希望大家及时指出。
相关文章推荐
- Oracle游标使用详解
- oracle 查询前一小时、一天、一个月、一年的数据
- 关于oracle登录出现ORACLE initialization or shutdown in progress
- Oracle中ROWNUM的使用技巧
- Oracle:grouping和rollup
- Oracle分组函数之ROLLUP
- Oracle clusterware的组成
- Oracle中的NVL函数
- 常用Oracle函数记录
- Oracle游标
- Oracle包的概念
- Oracle 密码过去解决方法
- Oracle 忘记sys或者system密码解决方法
- oracle查找重复记录
- oracle 进阶(二) oracle 其他数据库对象
- 新手Oracle安装及使用入门
- ORACLE RMAN增量备份经典理解
- UDEV SCSI Rules Configuration for ASM in Oracle Linux 5 and 6
- oracle恢复数据库数据到一个点
- powerdesigner 连接 oracle