oracle/函数

          1  sum(decode(fun_is(id, aid),1,1,0) = 1 )

             decode(待比较的对象,如果为这个,那麼结果为这个,否则结果是这个)


          2 distinct

           select distinct name ,id from table

            实际上是根据name+id  进行去重复的

        --distinct   只能放在句子的前面  否则会报错

                                   统计函数 

--统计函数

avg( distinct ) --去掉重复值再求平均值
max()
min()
sum(distinct)
count(dintinct ) --忽略重复的行 返回数据的行数
count(*)        -- 返回表中所有记录的行数

--使用统计函数 必然会用到  group by  子句   或者  having   (condition)

                 

                                        字符串函数                                                         


     3、substr('c ',&a,&b )

select substr('hello world',0,1) from  dual 
           --结果  h
select substr('hello world',1,1) from  dual 
           --结果  h
select substr('hello world',2,1) from  dual 
           --结果 e
select substr('hello world',2,5) from  dual 
          --结果 ello 
   --  a是开始符 b 是截取的长度
    

      4、trunc

--Oracle trunc()函数的用法
/**************日期********************/
1.select trunc(sysdate) from dual  --2011-3-18  今天的日期为2011-3-18
2.select trunc(sysdate, 'mm')   from   dual  --2011-3-1    返回当月第一天.
3.select trunc(sysdate,'yy') from dual  --2011-1-1       返回当年第一天
4.select trunc(sysdate,'dd') from dual  --2011-3-18    返回当前年月日
5.select trunc(sysdate,'yyyy') from dual  --2011-1-1   返回当年第一天
6.select trunc(sysdate,'d') from dual  --2011-3-13 (星期天)返回当前星期的第一天
7.select trunc(sysdate, 'hh') from dual   --2011-3-18 14:00:00   当前时间为14:41  
8.select trunc(sysdate, 'mi') from dual  --2011-3-18 14:41:00   TRUNC()函数没有秒的精确
/***************数字********************/
/*
TRUNC(number,num_digits)
Number 需要截尾取整的数字。
Num_digits 用于指定取整精度的数字。Num_digits 的默认值为 0。
TRUNC()函数截取时不进行四舍五入
*/
9.select trunc(123.458) from dual --123
10.select trunc(123.458,0) from dual --123
11.select trunc(123.458,1) from dual --123.4
12.select trunc(123.458,-1) from dual --120
13.select trunc(123.458,-4) from dual --0
14.select trunc(123.458,4) from dual  --123.458
15.select trunc(123) from dual  --123
16.select trunc(123,1) from dual --123
17.select trunc(123,-1) from dual --120

-- concat(string1,string2)连接两个字符串
select  concat('hello','world') from  dual   --helloworld
    --连接两个字段
    select concat(t.year,t.drink ) from   test_table  t --2013coffee
    select  t.year||t.drink   from  test_table t 

--length返回字符串的长度
select length('wo') from  dual  --2


--lower全部字母变为小写
select LOWER('IMPORT_FRWD_RATIO_ZHISHU_D') from dual   --import_frwd_ratio_zhishu_d

--upper全部字母变成大写

select upper('import_frwd_ratio_zhishu_d') from dual   --IMPORT_FRWD_RATIO_ZHISHU_D


--initcap首字母变成大写  其余字母不变
select  initcap('helloWorld') from  dual   --Helloworld


--instr(string,value)查询字符value 在字符串string 中出现的位置
   --instr( string1, string2 [, start position [, nth appearance ] ] )
   select instr('wo','w') from dual   --1  
   SELECT instr('syranmo','an',-1,1) FROM dual; -- 返回 4
   SELECT instr('syranmo','s') FROM dual; -- 返回 1  
   SELECT instr('syranmo','ra') FROM dual; -- 返回 3  SELECT instr('syran mo','a',1,2) FROM dual; -- 返回 0



    
    select t.*   from  test_table t  where  instr('coffee,softDrinks',t.drink)>0
    --等同于
    select t.*   from  test_table t  where t.drink in ('coffee','softDrinks')
    --等同于
    select t.*   from  test_table t  where t.drink='coffee' or t.drink='softDrinks'

    

    SELECT code, name, dept, occupation FROM staff WHERE instr(code, '001') > 0;  
       --等同于  
    SELECT code, name, dept, occupation FROM staff WHERE code LIKE '%001%' ;
        
    --从右边开始   查找第三个  l 
    select instr('hello,java world', 'l', -1, 3) from dual;--3




 日期函数

日期函数链接


   


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值