首页 技术 正文
技术 2022年11月8日
0 收藏 704 点赞 2,007 浏览 2477 个字

oracle基本的SQL语句和SQLSERVER基本一样,在这里只简单列出与SQLSERVER不一样的地方

1.select * from orderinfo where address = ‘abcd’  与 address = ‘ABCD’

得到的结果是不一样的,也就是说oracle字符区分大小写,这一点特别要注意。

2.查询语句中,如果表引用了别名,则字段也必须的用别名.字段名

select orderid, ordercode from orderinfo o是一条错误的查询语句,正确的如下:

select o.orderid, o.ordercode from orderinfo o或者select orderid , ordercode from orderinfo

3.A{operator}any B:表示A与B中的任何一个元素进行operator运算符的比较,只要有一个比较值为true,就返回数据行

A{operator}all B:表示A与B中的所有元素进行operator运算符的比较,只有所有元素的比较值都为true,就返回数据行

select * from orderinfo where orderid = any(1,2,3)    表示orderid等于1或2或3则返回数据行

select * from orderinfo where orderid <> all(1,2,3)    表示orderid不等于1并且不等于2并且不等于3则返回数据行

4.与null进行比较要用 is null这与sqlserver一样,在这里记一下

5.自然连接natural join

select o.orderid, u.userid from orderinfo o natural join userinfo u where o.orderid = 1

oracle把两个表中名称相同的列自动连接

6.子查询中的in, any ,all

select * from orderinfo where userid in (select userid from userinfo where username = ‘abcd’)与sqlserver一样

select * from orderinfo where userid > any (select userid from userinfo where username = ‘abcd’)

只要userid大于任何一个子查询中的userid则返回数据行

select * from orderinfo where userid > all(select userid from userinfo where username =’abcd’)

userid必须大于子查询中所有的userid才能返回数据行

7.insert语句

insert into orderinfo(orderid) values(orderinfo_seq.nextval)

orderinfo_seq.nextval获取序列下一个值,前提必须创建了orderinfo_seq序列

批量插入数据:

insert into orderinfo_tmp select * from orderinfo where orderid = 1

8.update语句

update orderinfo set mobilephone = ‘13333333333’ where orderid = 1

通过查询更新:

update orderinfo set (mobilephone, address, productnumeric, amount) = (select mobilephone,

address, productnumeric, amount from orderinfo where orderid = 1)

where orderid = 2

9.Delete,truncate语句

delete from orderinfo where orderid = 1

truncate table orderinfo –删除orderinfo表中所有的记录,并且不记录日志,所以可以很快的删除记录,但是无法恢复

10.事务

oracle11g中的事务是隐式自动开始的,它不需要用户显示地执行开始事务语句,但对于事务的结束处理,则需要用户进行指定的操作,

通常在以下情况oracle认为一个事务结束了:

1.执行commit语句提交事务

2.执行rollback语句撤消事务

3.执行一条数据定义语句,如create,drop,alter等语句,如果语句执行成功,oracle系统会自动执行commit命令,否则系统会自动执行

rollback命令

4.执行一个数据控制命令,比如grant,revoke,这种语句执行完毕,系统会自动执行commit命令

5.正常地断开数据库连接,正常退出sqlplus环境,系统会自动执行commit命令,否则系统自动执行rollback命令

综合上述五种情况,归根到底事务的结束要么执行commit命令,要么执行rollback命令

提交事务:

insert into orderinfo (orderid,…) values(orderinfo_seq.nextval,…);

commit;

回滚事务:

insert into orderinfo (orderid,…) values(orderinfo_seq.nextval,…);

rollback;

事务可以回滚到一个点,如:

truncate table orderinfo

insert into orderinfo (orderid,…) values(orderinfo_seq.nextval,…);

savepoint sp;

insert into orderinfo (orderid,…) values(orderinfo_seq.nextval,…);

rollback to savepoint sp;

commit;

上述语句执行后数据表中只有一条记录,也就是每一条插入语句所插入的数据

12.分页查询

select * from(
select o.*, rownum r from orderinfo o where rownum <=20 order by o.orderid asc)
where r > 10

查询第11-20条记录

相关推荐
python开发_常用的python模块及安装方法
adodb:我们领导推荐的数据库连接组件bsddb3:BerkeleyDB的连接组件Cheetah-1.0:我比较喜欢这个版本的cheeta…
日期:2022-11-24 点赞:878 阅读:9,492
Educational Codeforces Round 11 C. Hard Process 二分
C. Hard Process题目连接:http://www.codeforces.com/contest/660/problem/CDes…
日期:2022-11-24 点赞:807 阅读:5,907
下载Ubuntn 17.04 内核源代码
zengkefu@server1:/usr/src$ uname -aLinux server1 4.10.0-19-generic #21…
日期:2022-11-24 点赞:569 阅读:6,740
可用Active Desktop Calendar V7.86 注册码序列号
可用Active Desktop Calendar V7.86 注册码序列号Name: www.greendown.cn Code: &nb…
日期:2022-11-24 点赞:733 阅读:6,494
Android调用系统相机、自定义相机、处理大图片
Android调用系统相机和自定义相机实例本博文主要是介绍了android上使用相机进行拍照并显示的两种方式,并且由于涉及到要把拍到的照片显…
日期:2022-11-24 点赞:512 阅读:8,132
Struts的使用
一、Struts2的获取  Struts的官方网站为:http://struts.apache.org/  下载完Struts2的jar包,…
日期:2022-11-24 点赞:671 阅读:5,295