资源描述:
《oracle笔记 三、function 、select》由会员上传分享,免费在线阅读,更多相关内容在行业资料-天天文库。
1、重庆达渝仁科技官网:www.cqdyr.comScott表下有这么几个常用的表,而且还带有数据。分别是emp、dept、salgrade;1、查看表结构用descdescemp;2、空表dual,最常用的空表,如:select2*4fromdual;selectsysdatefromdual;3、双引号能保持格式如:selectsysdate“toDay日期”fromdual;4、
2、
3、字符串连接如:select2*3
4、
5、8fromdual;selectename
6、
7、salfromscott.emp;selectename
8、
9、‘ORACLE’fromscott.emp;5、单
10、引号,如:select2*2
11、
12、'abc''efg'fromdual;用两个单引号表示一个单引号6、去掉重复数据distinctselectdistinctdeptnofromscott.emp;去掉重复组合:selectdistinctdeptno,jobfromscott.emp;7、where查询A、=查询,select*fromscott.empwheresal=1500;B、比较<、>、>=、<=select*fromscott.empwheresal>1500;C、andorselect*fromscott.empwheresal>1500andsal<=500
13、0ordeptno=10;D、in、notinselect*fromscott.empwheresalin(1500,800)anddeptnonotin(10,20)E、like模糊escape转义Select*fromscott.empwhereenamelike‘%in%’;Select*fromscott.empwhereenamelike‘%in%k%’;Select*fromscott.empwhereenamelike‘%in#%k%’escape‘#’;表示like中的#号是转义字符,相当于F、isnull、isnotnullK、orderbyselec
14、tsal,enamefromscott.emporderbysal;selectsal,enamefromscott.emporderbysalasc;重庆达渝仁科技官网:www.cqdyr.comselectsal,enamefromscott.emporderbysaldesc;selectsal,enamefromscott.empwheresal>2000orderbysaldesc;selectsal,deptno,enamefromscott.emporderbysal,deptnodesc;8、functionA、lower、upper、substrselec
15、tlower(‘abcABC’)fromdual;selectupper(‘abcABC’)fromdual;substr(target,startIndex,length)selectsubstr(‘abcABC’,1,3)fromdual;B、chr、ascii将数字安装ascii值转换成字符:selectchar(65)fromdual;将字符转换成ascii值:selectascii(‘Z’)fromdual;C、round、to_char精确小数selectround(22.456)fromdual;保留2位小数:selectround(22.456,2)from
16、dual;精确到个位:selectround(22.456,-1)fromdual;货币设置货币格式,000前面不足就用0代替selectto_char(sal,'$000,000.00')fromscott.emp;999就不会替换不足的地方,只会安装格式输出selectto_char(sal,'$999,999.99')fromscott.emp;本地货币格式selectto_char(sal,'L999,999.99')fromscott.emp;日期日期格式格式控制描述YYYY、YYY、YY分别代表4位、3位、2位的数字年YEAR年的拼写MM数字月MONTH月的全拼
17、MON月的缩写DD数字日DAY星期的全拼DY星期的缩写AM表示上午或者下午HH24、HH1212小时制或24小时制MI分钟SS秒钟重庆达渝仁科技官网:www.cqdyr.comSP数字的拼写TH数字的序数词“特殊字符”假如特殊字符HH24:MI:SSAM15:43:20PMselectto_char(sysdate,'YYYY-MM-DDHH:MI:SS')fromdual;selectto_char(sysdate,'YYYY-MM-DDHH24:MI:SS')fromdual;D、to_date、to_numb