|
select to_char(sysdate,‘yyyy-mm-dd hh24:mi:ss‘) currenttime, to_char(sysdate - interval ‘7‘ year,‘yyyy-mm-dd hh24:mi:ss‘) intervalyear, to_char(sysdate - interval ‘7‘ month,‘yyyy-mm-dd hh24:mi:ss‘) intervalMonth, to_char(sysdate - interval ‘7‘ day,‘yyyy-mm-dd hh24:mi:ss‘) intervalday, to_char(sysdate - interval ‘7‘ hour,‘yyyy-mm-dd hh24:mi:ss‘) intervalHour, to_char(sysdate - interval ‘7‘ minute,‘yyyy-mm-dd hh24:mi:ss‘) intervalMinute, to_char(sysdate - interval ‘7‘ second,‘yyyy-mm-dd hh24:mi:ss‘) intervalSecond from dual;
6)add_months
select add_months(sysdate,12) newtime from dual; 7)extract
select extract(month from sysdate) "This Month", extract(year from add_months(sysdate,36)) " Years" from dual;
字符函数 --字符函数 select substr(‘abcdefg‘,1,5)substr,--字符串截取 instr(‘abcdefg‘,‘bc‘) instr,--查找子串
‘Hello‘||‘World‘ concat,--连接
trim(‘ wish ‘) trim,--去前后空格 rtrim(‘wish ‘) rtrim,--去后面空格 ltrim(‘ wish‘) ltrim,--去前面空格
trim(leading ‘w‘ from ‘wish‘) deleteprefix,--去前缀 trim(trailing ‘h‘ from ‘wish‘) deletetrailing,--去后缀 trim(‘w‘ from ‘wish‘) trim1,
ascii(‘A‘) A1, ascii(‘a‘) A2,--ascii(转换为对应的十进制数) chr(65) C1, chr(97) C2,--chr(十进制转对应字符)
length(‘abcdefg‘) len,--length
lower(‘WISH‘)lower, upper(‘wish‘)upper, initcap(‘wish‘)initcap,--大小写变换
replace(‘wish1‘,‘1‘,‘youhappy‘) replace,--替换
translate(‘wish1‘,‘y‘)translate,--转换,对应一位(前面的位数大于等于后面的位数) translate(‘wish1‘,‘sh1‘,‘hy‘)translate1,
concat(‘11‘,‘22‘) concat --连接
from dual;
to_number --to_number(expr) --to_number(expr,format) --to_number(expr,format,‘nls-param‘)
select to_number(‘0123‘)number1,--converts a string to number trunc(to_number(‘0123.123‘),2) number2, to_number(‘120.11‘,‘999.99‘) number3, to_number(‘0a‘,‘xx‘) number4,--converts a hex number to decimal to_number(100000,‘xxxxxx‘) number5
from dual;
聚合函数 student表如下:
count:
--count (distinct|all) select count(1) as count from student;--效率最高 select count(*) as count from student; select count(distinct score) from student; 语句1结果:11
avg
--avg (distinct|all) select avg(score) score from student; select avg(distinct score) from student; select classno,avg(score) score from student group by classno; 语句3输出结果:
?
max
--max (distinct|all) select max(score) from student; select classno,max(score) score from student group by classno; min
--min (distinct|all) select min(score) from student; select classno,min(score) score from student group by classno; stddev(standard deviation)标准差
--stddev select stddev(score) from student; select classno,stddev(score) score from student group by classno; sum
--sum select sum(score) from student; select classno,sum(score) score from student group by classno; median--中位数
(编辑:PHP编程网 - 湛江站长网)
【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!
|