常用的sql语句,如建表、建索引、建约束条件;以及增删改查和高级查询操作
to_date(字符串,格式) --将字符串按照指定的格式转换成date数据类型
--4.4 基本查询
--4.4.1 select语句
select 列1,列2,...,列n from 表 where 条件 order by 列
select user_id,user_name,user_pass,user_birthday,user_nickname from bbs_user;
select * from bbs_user; --效率低
--4.4.2 基本查询
--4.4.2.1 包含算数表达式(number、null、date)
select user_id,user_name,user_pass,user_birthday,user_birthday+10
from bbs_user;
select user_id *0.25 + 100 ,user_id,user_pass,user_name
from bbs_user;
select topic_id,topic_title,topic_user_id,
(topic_user_id + 100)/2.5*0.35,
(topic_last_reply_user_id + 100)*3.5/0.34
from bbs_topic;
--4.4.2.2 包含连接表达式
select topic_id,topic_title,topic_title || '-->这里是测试数据'
from bbs_topic;
select topic_id,topic_title,topic_title || '-->这里是测试数据' || '-->系统时间:' || to_char(sysdate,'yyyy-mm-dd hh24:mi:ss')
from bbs_topic;
--4.4.2.3 空值的使用
--在null值身上进行任何操作得到结果均为null
--4.4.2.4 字段别名、表别名
select * from bbs_user;
select user_id as 编号,user_name as 登录名,user_pass as 密码,user_nickname as 昵称
from bbs_user;
select user_id as "my name",user_name as "我的 登录名",user_pass as 密码,user_nickname as 昵称
from bbs_user;
select er_id as 编号, er_name as 登录名
from bbs_user u;
--4.4.2.5 文本字符串
select user_id as 编号, '你爷爷' as 姓名
from bbs_user;
--4.4.2.6 去掉重复值
select * from bbs_user_section;
select distinct us_user_id from bbs_user_section;
--4.4.3 带有限制条件的查询
--4.4.3.1 where语句
语法:
select 列1,列2,...,列n
from 表
where 条件
--4.4.3.2 where中的比较操作符
> < >= <= <> =
select * from bbs_user;
select * from bbs_user where user_gender = '男';
select * from bbs_user where user_gender <> '男';
select * from bbs_user
where user_birthday> to_date('1989-12-31','yyyy-mm-dd');
select * from bbs_topic;
select * from bbs_reply;
--4.4.3.3 where中的逻辑运算符
and or not
select * from bbs_user
where us
er_gender <> '男' and user_birthday> to_date('1989-12-31','yyyy-mm-dd');
like -- 通配符 %(任意长度的任意字符) _(一个长度的任意字符)
select * from bbs_use
搜索“diyifanwen.net”或“第一范文网”即可找到本站免费阅读全部范文。收藏本站方便下次阅读,第一范文网,提供最新资格考试认证oracle中的常用sql语句(7)全文阅读和word下载服务。
相关推荐: