zoukankan      html  css  js  c++  java
  • infoepo sql用法整理

    用的较多的函数:round、sum、 decode()、nvl()、 left join、 group by 、to_number(varchar2)


    round(sum(nvl(to_number(ta.curr_year_inv_at), 0))/10000,2) as curr_year_inv_at
    decode(ta.unit_in_charge, '1', '省管', '2', '市管', '3', '集团') as unit_name,
    group by ta.unit_in_charge

    ------------------------------------------------substr()
    /**默认过滤当前年数据**/
    hsqlbuffer.append(" and substr(t.project_cd,2,2) =:applyyear ");
    paraMap.put("applyyear", searchBean.getApplyyear().substring(2));

    --substr(字符串,截取开始位置,截取长度)=返回截取的字
    select substr('miaoying',0,1) from dual;--返回结果为:m
    select substr('miaoying',1,1) from dual;--返回结果为:m--说明0和1都表示截取的位置为第一个字符
    select substr('miaoying',-7,4) from dual;--返回结果为:iaoy--负数表示:-7表示从右边开始数第七位开始,也就是i,截取长度为4的字符串

    -------------------------------------------------instr();
    instr函数在Oracle/PLSQL中是返回要截取的字符串在源字符串中的位置
    from t_pc_project_moneymaintain t1
    join v_project_money t2
    on t1.citycode = t2.citycode and instr(t1.project_cd,t2.project_cd) != 0


    eg:

    --instr(源字符串,目标字符串,起始字符串,匹配字符串)=返回要截取的字符串在源字符串中的位置,从字符的开始,只检索一次
    --instr(string1,string2,index1,index2) 表示:要在string1的index1号位置,开始查找,第index2次,出现的string2
    select instr('miaoying','i',2,2) from dual;--返回6:也就是说:在"miaoying"的第2号位置开始,查找第二次出现的i的位置
    select instr('miaoying','k',2,2)from dual;--返回0:即如果查找不到,则返回0
    select instr('miaoying','i') from dual;--返回2
    select instr('miaoying','yi') from dual;--返回5:即"yi"的y的位置
    select instr('miaoying','i',-1,2) from dual;--返回2:
    --空格也是字符。。。。。

    select * from omgnode a where name like '%miaoying%'
    select * from omgnode a where instr(name,'miaoying')>0--效果一样
    --------------------------------------------------------------------------------------round 函数:四舍五入后保留几位小数点
    如何使用 Oracle Round 函数 (四舍五入)
    描述 : 传回一个数值,该数值是按照指定的小数位元数进行四舍五入运算的结果。
    SELECT ROUND( number, [ decimal_places ] ) FROM DUAL
    参数:
    number : 欲处理之数值
    decimal_places : 四舍五入 , 小数取几位 ( 预设为 0 )
    Sample :
    select round(123.456, 0) from dual; 回传 123
    select round(123.456, 1) from dual; 回传 123.5
    select round(123.456, 2) from dual; 回传 123.46
    select round(123.456, 3) from dual; 回传 123.456
    select round(-123.456, 2) from dual; 回传 -123.46

    --------------------------------------------------------------------------------------sign 函数: 函数返回一个数字的正负标志.
    sign 函数返回一个数字的正负标志.
    语法如下:sign( number )
    number 要测试标志的数字.
    If number < 0, then sign returns -1.
    If number = 0, then sign returns 0.
    If number > 0, then sign returns 1.
    应用于:
    Oracle 8i, Oracle 9i, Oracle 10g, Oracle 11g
    例如:
    sign(-23)
    would return -1
    sign(-0.001)
    would return -1
    sign(0)
    would return 0
    sign(0.001)
    would return 1
    sign(23)
    would return 1
    sig(23.601)
    would return 1

  • 相关阅读:
    [.NET]如何擷取部分網頁內容轉成圖片
    一些很有用的JS特效
    Response. AppendHeader使用大全及文件下载.net函数使用注意点(转载)
    .NET获取客户端信息
    WAYOS 破解版三天重启最新解决办法,免重启程序
    MySQL 随机生成各种类型的随机函数
    Active Form显示标题栏及页面跳转
    wayos计费系统easyradius使用小记
    ROS中的智能QOS实现,效果应该是会比WAYOS好,而且更灵活
    以太网中的ARP和PPPOE
  • 原文地址:https://www.cnblogs.com/21heshang/p/8033884.html
Copyright © 2011-2022 走看看