zoukankan      html  css  js  c++  java
  • oracle 常用 sql

    判断字段值是否为空( mysql 为 ifnull(,)):

    nvl (Withinfocode,'') as ***

    两字段拼接:

    (1)concat(t.indate,  t.intime) as 就诊时间

    (2)和其他数据库系统类似,Oracle字符串连接使用“||”进行字符串拼接,其使用方式和MSSQLServer中的加号“+”一样。

    SUBSTR(t.DiagnoseTime,1,4)||'-'||SUBSTR(t.DiagnoseTime,5,2)||'-'||SUBSTR(t.DiagnoseTime,7,2)

    ||'-'||(case t.PatientMFlag when '0' then '住院'  when '1' then '门诊' else ' ' end) as visitKey

    原字符串 (20031202154726)可拼接成【2004-06-17-住院】

    字符串截取:

    SUBSTR(t.DiagnoseTime,1,8) 

    第一个字符开始,取 8 个。对于日期时间字符串"20031202154726"会得到 "20031202"

    日期时间格式化: 

    to_date(concat(t.indate,t.intime),'yyyy-MM-dd HH24:mi:ss')

    我们还需要以24小时的形式显示出要用的HH24 

    select to_char(sysdate,'yyyy-MM-dd HH24:mi:ss') from dual;//mi是分钟

    select to_char(sysdate,'yyyy-MM-dd HH24:mm:ss') from dual;//mm会显示月份

    select * from tpoolhourinfo a where a.workdate between to_date('2008-8-20','yyyy-mm-dd') 
    and to_date('2008-8-25','yyyy-mm-dd')

    只取日期:

    20031202154726

    to_date(SUBSTR(t.DiagnoseTime,1,8),'yyyy-MM-dd') as visitDate 

    抽样: 

    SELECT   MRID,
    case PaperType  when '0'  then '0-身份证' when '1' then '1-军人证' when '2' then '2-其它' else null  end as 证件类型,
     PaperNum as 证件号码,
     McNum as 医保号
    FROM   MainMr SAMPLE (0.07)

  • 相关阅读:
    KVM之一:安装准备(基于CentOS6.7)
    Nginx技巧——Nginx/Apache下禁止指定目录运行PHP脚本(转自运维之美)
    (转)关于 awk 的 pattern(模式)
    form验证里使用request 和前端倒计时
    restful 在接口中获取 传过来的值
    django使用celery
    celery
    restful 在接口中获取 request.user
    码云创建一个仓库
    django中local_settings的配置
  • 原文地址:https://www.cnblogs.com/quietwalk/p/9055204.html
Copyright © 2011-2022 走看看