常用的sql语句,如建表、建索引、建约束条件;以及增删改查和高级查询操作
r
where user_name like '%A%'; --字符串大小写敏感
select * from bbs_user where user_name like '%a%' or user_name like '%A%';
select * from bbs_user where user_name not like '%a%';
select * from bbs_user where user_nickname like '_张%';
in -- 指定在某个范围之内
select * from bbs_user where user_gender in ('男','女');
select * from bbs_topic where topic_reply_count in (0,5);
select * from bbs_user where user_gender not in ('男','女');
--查询空值
select * from bbs_topic;
select * from bbs_topic where topic_last_reply_date is null;
select * from bbs_topic where topic_last_reply_date is not null;
--
select * from bbs_user
where user_birthday >= to_date('1985-01-01','yyyy-mm-dd')
and
user_birthday <= to_date('1989-12-31','yyyy-mm-dd');
select * from bbs_user
where user_birthday between to_date('1985-09-12 00:00:00','yyyy-mm-dd hh24:mi:ss')
and to_date('1989-03-28 23:59:59','yyyy-mm-dd hh24:mi:ss');
--4.4.4 给查询结果排序
语法:
select 列名
from 表
where 条件
order by 列 [ASC | DESC]
select * from bbs_topic order by topic_id desc;
select * from bbs_topic order by topic_date asc;
select * from bbs_topic
order by topic_date, topic_id; --按照topic_date排序,若有相同值则按照topic_id排序
---------------------------第五章 高级查询-----------------------------------
--5.1 函数查询
--5.1.1 单行函数
--5.1.1.1 字符函数
--5.1.1.2 数字函数
--5.1.1.3 日期函数
--5.1.1.4 转换函数
--5.1.1.5 其他函数
--5.1.2 分组函数
--5.1.2.1 常用分组函数
--5.1.2.2 使用group by对数据分组
--5.1.2.3 使用having对组结果进行限制
--5.2 多表连接查询
--5.2.1 多表链接分类
--5.2.2 等值连接
--5.2.3 非等值连接
--5.2.4 外连接
--5.2.5 自连接
--5.3 子查询
--5.3.1 子查询类型
--5.3.2 单行子查询
--5.3.3 多行子查询
--5.3.4 多列字查询
--5.1 函数查询
--5.1.1 单行函数
--5.1.1.1 字符函数
lower(char)
select lower('THIS IS A VERY NICE MORNING. hello') as 问好 from dual;
select lower('大家早上好,你们好吗?') as 问好 from dual;
upper(char)
select upper('i love this game. NBA.') from dual;
initcap(ch
ar)
select initcap('i love this game. NBA. 我爱这个游戏!') from dual;
select initcap('i love this game.') || 'NBA' from dual;
ascii(char
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新资格考试认证oracle中的常用sql语句(8)全文阅读和word下载服务。
相关推荐: