• 第10章 单行函数 ​


    第10章 单行函数
    可以将函数广泛的分为单行函数和多行函数
    select * from test3 order by tnum desc
     
    select bdz_id, shebei_id, shebei_name, user_id
      from tf_dev_ctrl
     where bdz_id = &BDZID
     order by bdz_id, user_id desc
     
    select bdz_id, mingzi, &&col
      from tf_substation
     where mingzi is not null
     order by &col
     
     
     select bdz_id , mingzi, length(mingzi) as length
    from tf_substation
     
     lower(s) s代表字符串 小写
     upper(s) s代表字符串 大写
     initcap(s) 首字母大写
     concat(s1,s2) 连接两个字符串
     length(s) 字符数
     lpad(s,n,p) rpad(s,n,p)
     select initcap('hello world') from dual
      //Hello World
     select concat('today is:',sysdate) from dual
      //Today Is:22-12月-17 
     
     select lpad('12',5,'02') lad from dual
      //02012
     select rpad('12',5,'02') lad from dual
      //12020
     
     select trim(both '*' from '****hiddle******') trims from dual
     //hiddle
     select trim(leading '*' from '****hiddle******') trims from dual
     //hiddle******
     select trim(trailing '*' from '****hiddle******') trims from dual
      ****hiddle
      
     select instr('1#3#5#7','#') from dual   //2
      select instr('1#3#5#7','#',5) from dual  //6
     
     select instr('1#3#5#7#9#','#',3,4) from dual
     //10 位置3开始第四次出现位置为10
     instr和substr配合使用,从电子数据流中提取已编码的数据
    select substr('1#3#5#7#9#',5) from dual //5#7#9#
    select substr('1#3#5#7#9#',5,3) from dual //5#7
    select substr('1#3#5#7#9#',-3,3) from dual //#9#
     
     select replace('1#3#5#7#9#','#') from dual //13579
    select replace('1#3#5#7#9#','#','->') from dual //1->3->5->7->9->
     
    select round(1601.916,1) from dual //1601.9
    select round(1601.916,2) from dual //1601.92
    select round(1601.916,-3) from dual //2000
    select round(1601.916) from dual //1602
     
     select trunc(1601.916,1) from dual //1601.9
    select trunc(1601.916,2) from dual //1601.91
    select trunc(1601.916,-3) from dual //1000
    select trunc(1601.916) from dual //1601
     
     select mod(6,2) from dual //0
     select mod(5,3) from dual //2
     select mod(7,35) from dual //7
     select mod(5.2,3) from dual //2.2
    所有偶数除以2都没有余数,但是奇数除以2的余数是1。
    因此mod函数用来区分偶数和奇数。
     
    select months_between(sysdate,sysdate-31)*31 from dual
    两个日期之间月份的差值,以31天算。
    add_months(startdate,number) 月份加number
     
    返回给定日期的最后一天
    select last_day(sysdate) from dual 
    sysdate=2017/12/22 16:07:18
    返回2017/12/31 16:07:18
     
    select substr('zyb@gmail.com',
                  instr('zyb@gmail.com', '@') + 1,
                  instr('zyb@gmail.com', '.com')
    - instr('zyb@gmail.com', '@') - 1) mail
      from dual --gmail
     
    to_number函数将字符转化成数字,
    to_number(123.56,'999.9')返回错误,
    to_char(123.56,'999.9')返回123.6
     
    select nvl(null,1234) from dual //1234
    nvl函数可用于将null的数字值转化成0
     
    select nvl2(12,123,456) from dual//123
    select nvl2(null,123,456) from dual//456
     
    nullif(123,123) //返回空
    nullif(123,456) //返回123
    相等返回空,不相等返回第一项
     
    nvl(original,ifnull)非空返回original,空返回ifnull
    nvl2(original,ifnotnull,ifnull)
    coalesce(p1,p2,..)返回第一个非空的值。p1,p2必须。
     
    select decode('search','com1','true1','com2','true2','search','true3','iffalse')
    返回true3.
     
    select case substr(1234, 1, 3)
             when '134' then
              '1234 is match'
             when '1235' then
              '1235 is match'
             when concat('1', '23') then
              concat('1', '23') || ' is match'
           end
      from dual //123 is match

  • 相关阅读:
    leetcode 334. Increasing Triplet Subsequence
    leetcode 235. Lowest Common Ancestor of a Binary Search Tree
    leetcode 459. Repeated Substring Pattern
    python爬虫之Xpath
    python爬虫之bs4 美丽汤
    python3爬虫的模拟浏览器
    python爬虫之requests库
    ModelForm:表单中的 Field 和模型中的 Field重复解决
    django中关于表单自定义验证器和常用验证器
    关于http连接的本质 已经cookies和session
  • 原文地址:https://www.cnblogs.com/zhangyuanbo12358/p/9184818.html
Copyright © 2020-2023  润新知