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)

  • 相关阅读:
    Poj(1703),种类并查集
    Poj(2236),简单并查集
    Poj (3239),m皇后问题
    Poj(1521),哈夫曼编码
    NYOJ(680),摘枇杷,(暴力,或者二分搜索)
    NYOJ(42)欧拉图
    数集合有多少个TOJ(2469)
    HDU(1016),打素数环
    HDU(4394),数论上的BFS
    Poj(2225),三维BFS
  • 原文地址:https://www.cnblogs.com/quietwalk/p/9055204.html
Copyright © 2011-2022 走看看