oracle 基础查询语句

select abs(10) from dual; --取绝对值
select ceil(3.6) from dual;--向上取整

select power(2,3) from dual;--2的3次方

select mod(100,3)from dual;--取余

select sqrt(64) from dual;--开方

select sign(0) from dual; --如何是负数返回-1,如果是0返回0,如果是正数返回1

select initcap('heLlo') from dual; --函数INITCAP()是将每个单词的第一个字母大写,其它字母变为小写返回.

select lower('hELlo') from dual;   --大写换小写

select length('abcd') from dual;  --求长度

select Ltrim('abcdefghijklmnopq','abc') from dual; --截掉开头

select replace('abcde','bc','fd') from dual; --替换

select instr('abc','c') from dual;  --找下标

select substr('abcdedf',2,4) from dual; --截取字符串,从第二个开始,截取四个

select concat('123','abc') from dual; --拼接字符串

select sysdate from dual; --获取当前时间

select ceil(abs(months_between(sysdate,to_date('2018-12-12','yyyy-mm-dd')))) from dual; --求两个时间点的月数差

select add_months(sysdate,12) from dual; --当前时间加12个月

select next_day(sysdate,7) from dual; --当前时间所在周的第7天

select last_day(sysdate) from dual; --当前月的最后一天

select to_char(sysdate,'yy"年"-mm"月份"-dd') from dual; --日期转换成字符串
 
select to_char(sysdate,'MON') from dual; --当前月

select to_char(sysdate,'DDD') from dual; --本年的第几天

select to_char(sysdate,'DD') from dual; --本月的第几天
 
select to_char(sysdate,'D') from dual; --本周第几天

select to_char(sysdate,'Q') from dual; --本年第几季度

select to_char(sysdate,'DY') from dual; --返回当前日期是星期几

select to_char(sysdate,'yyyy-mm-dd HH24:MI:SS') from dual; --返回当前日月年时分秒

select to_date('2018-12-12','yyyy/MM/dd') from dual; --将日期转换为字符串

select nvl('A','B') from dual; --如果A为空或空窜则取B

  -- trunc
   select sysdate from dual;
   select trunc(109.456,-1)from dual; --以小数点为基准,取小数点之前一位的数的值 值为100,trunc(109.456,1)值为109.4,,trunc(109.456,2)值为109.45 。。。。
   select trunc(sysdate,'YY') from dual;-- 取当前日期所在年份第一天
   select trunc(sysdate,'MM') from dual; -- 当前日期所在月份的第一天
   select trunc(to_date('2018-7-19','yyyy-mm-dd'),'D') from dual;-- 本周的第一天
   select trunc(to_date('2018-12-19','yyyy-mm-dd'),'Q') from dual;--当前日期所在季度的第一个月的第一天
   
    SELECT NEXT_DAY(trunc(sysdate,'MM'),2) FROM DUAL; --当月第一天所在周的第二天

posted @ 2018-07-23 17:23  温碧泉  阅读(386)  评论(0编辑  收藏  举报