小夜埙
路很长,要耐心,慢慢走!

最近工作中遇到了一些与oracle相关的问题,稍微整理一些工作中用到的SQL语句

时间相关

--查询距当前时间十分钟内的数据
select sysdate -interval '10' minute as time from dual;

--查询距当前时间十天内的数据
select sysdate -interval '10' day as time from dual;

--查询年月日 时分秒
select to_char(sysdate,'yyyy-MM-dd HH24:mm:ss') as time from dual

数值处理

--小数点前的0不显示
select to_char(0.58740,'fm99990.0099') from dual

基本语法

--case when then 语句
 select
    (case a.cjrlx 
               when '1' then '0'
               when '2' then '1'
               when '3' then '2'
    end) as pasType --乘机人类型
        from kh_khddcjr a

基本函数

    --decode函数的基本用法
    --M:男  F:女
    --相当于 if--else if--else 语句,如果性别是M,返回1,如果是F,返回2,如果还有其它的,可以接着写下去。感觉和case--when 挺像。
    select decode(k.xb,'M','1','F','2') as xb from  user k;

    
    --NVL函数
    --主要作用是从两个表达式返回一个非 null 值。
    --如果eExpression1的值是null,就返回eExpression2的值
    select NVL(k.xcdh,'000') as scdh from user k

数据处理

    --查询某个字段是否有重复的
    select g.wxid,count(*) from BASE_GETWXID g group by g.wxid having count(*) > 1
posted on 2018-01-20 11:51  小夜埙  阅读(274)  评论(0编辑  收藏  举报