PL-SQL温习

1.SELECT PRODUCT_NAME, PRODUCT_PRICE*0.8 FROM PRODUCT

此处可以直接用乘法,取出的是打折后的价格

---------------------------------------------------------------------------------------------------------------

2.select user_name,to_char(sysdate,'YYYY')-to_char(user_birthday,'YYYY') as user_age from user

此处可以用to_char函数计算出日期的年部分,然后相减得出用户的年龄

---------------------------------------------------------------------------------------------------------------

3.select user_birthday from user where between '1-1-83' and '1-1-84'

检索生日大于83年1月1日,且小于84年1月1日的;与之相反,not between ... and ...则是大于等于下限值,小于等于上限值

---------------------------------------------------------------------------------------------------------------

4.通配符

_:一个下划线表示任意单个字符

%:表示任意多个字符(含0个字符)

[abc]或[a-c]:属于字符集合中的任意一个字符

[^abc]或[^a-c]:不属于字符几何中的任意一个字符

---------------------------------------------------------------------------------------------------------------

5.空值判断

is null不能用 = null  来代替;null也不等于''

---------------------------------------------------------------------------------------------------------------

6.rownum

select * from user where rownum <= 10

查询前10条;rownum是从1开始的!

---------------------------------------------------------------------------------------------------------------

7.group by

select categroy_id , count(product_id) from product group by category_id

一般group by 都会跟着统计函数在一起  如:count(...)

---------------------------------------------------------------------------------------------------------------

8.having

select categroy_id , count(product_id) from product group by category_id having count(product_id)>10

对分组的数据进行过滤,不能使用where子句,因为where子句在分组之前执行过滤,having子句在分组之后执行过滤

---------------------------------------------------------------------------------------------------------------

9.exists

select product_id from product where exists ( select * from important_product )

exists返回的是一个逻辑值;与之相反是not exists

---------------------------------------------------------------------------------------------------------------

10.All与any

select  price from product where price < all ( select price from important_product)

< all小于子查询结果集中的最小值

> all大于子查询结果集中的最大值

> any 大于子查询结果集中的最小值

< any 小于子查询结果集中的最大值

---------------------------------------------------------------------------------------------------------------

其他容易记住的就不一一列出了

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值