Oracle学习基础(二)

来源:互联网 发布:丽升网络评卷系统 编辑:程序博客网 时间:2024/05/13 12:11

1.      软件架构 C/S=client/server B/S=browser/server

2.      Upper(字段),将字段整列转换成大写

Select * from person where upper(name) = ‘TOM’;

3.      Avg(字段),求整列平均

Select avg(salary) from person;

4.      函数分类:单行函数,多行函数(组函数)

5.      字符函数:大小写转换

请以大写/小写/首字母大写的格式列出所有人的姓名

Select upper(name) from person;

Select lower(name) from person;

Select initcap(name) from person; //所有单词的首字母均大写

6.      字符函数:字符处理

请列出所有人名字的长度

Select length(name) from employees;//一个中英文长度均认为是1

请列出名字的第一个字(字符串截取)

Select substr(name,1,1) from employees;//第二个参数:截取的起始位置 第三个参数:截取的长度

如果name中有’abc’,则将其替换成java显示

Select replace(name,’abc’,’java’) from employees;

7.      数字函数

请列出所有人的工资,精确到小数点后2位(四舍五入)

Select round(salary,2) from employees;

Select round(salary) from employees;

请列出所有人的工资,精确到小数点后2位(直接截取)

Select trunc(salary,2) from employees;

Select trunc(salary) from employees;

8.      日期函数

请列出所有人的入职月数

Select months_between(sysdate,hireday) from employees;

请列出所有人入职的天数

Select sysdate-hireday from employees;

9.      日期函数截取

Round(’25-JUL-95’,’month’);à01-AUG-95

Round(’25-JUL-95’,’year’);à01-JAN-96

trunc(’25-JUL-95’,’month’);à01-JUL-95

trunc(’25-JUL-95’,’year’);à01-JAN-95

10.  转换函数

To_date(sysdate,’YYYY-MM-DD HH24-MI-SS’);

To_char(‘YYYY/MM/DD DAY’);//日期类型 DAY是指星期几

To_char(‘YYYY/MM/DD HH24:MI:SS’);//日期类型

Ex:

Select to_char(hireday,’YYYY”年”MM”月”DD”日”  DAY’) from employees;

11.  其它函数

NVL(expr1,expr2);将空值转换为实际的值,数据格式可以是日期,字符,数字,但数据类型必须匹配

NVL(comm,0)

NVL(hireday,’01-5月-08’)

NVl(name,’名字未知’)

Select NVL(name, ’名字未知’) fromemployees;

NVL2(expr,expr1,expr2);如果expr不为空,返回expr1,为空,返回expr2,expr可以为任何数据类型

如:

Insert into employees values(‘009’,’null’,’ 长春’,’24-1月-2009’,6000);

Select NVL2(name,’有名字’,’未知名字’) fromemployees;

练习:

/*

droptable employees;

createtable employees

(

  id varchar2(4),

  name varchar2(10),

  addr varchar2(20),

  hireday date,

  salary number(10,3)

);

insertinto employees values('001','ABVdef','北京','06-12月-1999',2000.234);

insertinto employees values('002','BBBadAA','哈尔滨','06-12月-1999',7600.345);

insertinto employees values('003','Tom','大连','06-3月-2008',7600.345);

insertinto employees values('004','刘德华','上海','06-3月-2008',1500.456);

insertinto employees values('005','黎明','大庆','06-3月-2008',2500.678);

insertinto employees values('006','张学友','海南','06-3月-2008',3000.789);

insertinto employees values('007','郭富城','福建','06-3月-2008',8000.876);

insertinto employees values('008','老刘','郑州','06-3月-2008',7000);

commit;

*/

--selectupper(name),salary from employees;

--selectname,salary,length(name) from employees;

--selectreplace(lower(name),'bad','good') from employees;

--selectreplace(lower(name),'bad','') from employees;

--insertinto employees values('013','rihana','北京',sysdate,7000);

--commit;

--selectto_char(hireday,'YYYY"年"-MM"月"-DD#DAY') from employees;

--6.求100天之后的日期

--selectsysdate+100 from employees;

--7.员工入职多少天了

--selectround(sysdate-hireday) from employees;

--8.员工入职多少个月了

--selecttrunc(months_between(sysdate,hireday)) from employees;

--9.昨天入职的人

--select* from employees whereto_char(sysdate-1,'YYYY-MM-DD')=to_char(hireday,'YYYY-MM-DD');

--select* from employees;

--updateemployees set id='010' where hireday = to_date('14-4-8','YYYY-MM-DD');

--commit;

--10.去年入职的人

--select* from employees where to_char(sysdate,'YYYY')-1=to_char(hireday,'YYYY');

--11.今年入职的人

--select* from employees where to_char(sysdate,'YYYY')=to_char(hireday,'YYYY');

--11.1 在2005年到2009年之间入职的人

--select* from employees where to_char(hireday,'YYYY') between 2005 and 2009;

--12.2008年和2014年入职的人

--select* from employees where to_char(hireday,'YYYY') IN(2008,2014);

--select* from employees where to_char(hireday,'YYYY')=2008 ORto_char(hireday,'YYYY')=2014;

--13.今天和昨天入职的并且姓张的人

/*

select *from employees where to_char(hireday,'YYYY-MM-DD')

IN(to_char(sysdate-1,'YYYY-MM-DD'),to_char(sysdate,'YYYY-MM-DD'))

AND

name LIKE'张%';

*/

--14.2008年3月份雇佣的人

--select* from employees where to_char(hireday,'YYYY-MM')='2008-03';

--15.今天早上6点以后入职的人员名字和入职的精确时间(格式匹配一定要注意)

selectname,to_char(hireday,'YYYY-MM-DD HH24:MI:SS') from employees

whereto_date(hireday,'YYYY-MM-DD HH24') > to_date(to_char(sysdate,'YYYY-MM-DD')||'06','YYYY-MM-DDHH24');

--select to_char(hireday,'YYYY-MM-DD HH24:MI:SS') fromemployees;

0 0
原创粉丝点击
热门问题 老师的惩罚 人脸识别 我在镇武司摸鱼那些年 重生之率土为王 我在大康的咸鱼生活 盘龙之生命进化 天生仙种 凡人之先天五行 春回大明朝 姑娘不必设防,我是瞎子 注册表删一项后电脑启动不了怎么办 解压过的过的软件安装包损坏怎么办 手机中病毒自动发短信扣费怎么办 苹果手机中的高德地图打不开怎么办 大晚上挂了别人的车怎么办 手机不兼容高版本微信怎么办 绝地求生右下角小地图变大了怎么办 杯孕当月做了C丁怎么办 玩全军出击手机发烫就出现卡怎么办 不小心买了彩虹六号肝帝版本怎么办 微信游戏刺激战场电脑卡怎么办 电脑更新了以前的东西都没了怎么办 安装黑苹果鼠标键盘不能用怎么办 苹果开机卡在白底黑苹果怎么办 信长之野望14没有剧情触发怎么办 玩cf手游手机屏幕摩擦力大怎么办 网吧有战地1没有橘子平台怎么办 俩人打仗了对方想讹我怎么办 环世界模组装多了打不开怎么办 手机百度云视频播放画面太小怎么办 ps文件说数据似乎已经损坏怎么办 百度云中的压缩包下载的很慢怎么办 游戏压缩出现未知错误或损坏怎么办 百度云里的压缩包解压后损坏怎么办 联创打印时显示压缩文件失败怎么办 电脑的软件打开出现未知格式怎么办 图片只突出人物边上全黑怎么办 合金机兵存档密码忘了怎么办 手机网页验证码无法加载插件怎么办 绝地求生次激战场机型不支持怎么办 木茷生存中文版安装包损坏了怎么办 手机下载软件显示安装包损坏怎么办 不小心把qq图片删了怎么办 奶水不足宝宝不好好吸奶怎么办 膀胱切除前列腺切除阴茎不硬怎么办 小孩的睾丸睾丸碰肿了怎么办 怎么判断小孩子的睾丸没下来怎么办 怀孕39周腰酸屁股酸疼该怎么办 我儿子18岁睾丸筋鼓起来怎么办 去医院检查说精子跑的慢怎么办 多囊卵巢综合症引起屁股增大怎么办