zoukankan      html  css  js  c++  java
  • 数据库基本常识【总结】

    Count (*) …group by ..计算相同的栏位个数(不能用Select * 的哦)

    Order by ..desc/asc:  升/降排序

    Rownum :       select的笔数(Oracle)

    select * from BOAT_RELATION_DTL where  rownum <='100'  order by  RELATION_DATE asc

    Limit  :      select的笔数(MysqL)

    select * from BOAT_RELATION_DTL   order by  RELATION_DATE desc  limit 100

    在数据库中添加新栏位  :'' AS Column_name

    数据库中update时间格式,需用to_date去转换:

     update  table_name

     set  EXPORTDATE= to_date('2011/01/17 08:06:23' ,'yyyy/mm/dd hh:mi:ss')

     where  条件

    時間轉換:

    Oracle: select to_char(sysdate,'yyyy/MM/dd HH:mm:ss') "現在時間"

    from dual

      SQL:  select convert(CHAR(19),GETDATE(),120) "現在時間:"

                                               Oracle                         SQl

    日期格式轉換成字型             to_char(date,’’)          年月日convert(char,111)

                                                                             24小時制:  convert(char ,120)

    從數值轉換成字串                to_char(int )                convert(char,int)

    從字串轉換成數值               to_char(string)         convert(string ,int )/cast(string as int)

    從字串到日期                     to_date(string)         convert(datetime,string)/cast(string as datetime)                                                  

     

    求的這個月最后的一天:

    Oracle :  select last_day(sysdate) “月底日期: ”

       select  to_char( last_day(sysdate),'yyyy/MM/dd HH:mm:ss') "月底日期: " from dual

    SQl:select                          

    dateadd(day,

            -1,

            convert(datetime,

                    (convert(char(7),

                             dateadd(month,

                                     1,           //第一:求的現在日期1個月后的日期

                                    getdate()

                                     ),

                              111

                              )+'/1'   //第二:取得下個月1日的日期

                       )

                    )

            )                      //求的本月的最後一天(下個月的1日減去1天就是了)

    求的兩個日期間的剩餘天數:

                  Oracle: select last_day(sysdate)-sysdate "剩餘"from dual

    字串的操作:

    連接:oracle: ||     null||null ==null,null||’ASV’=’ASV’

      SQL : + null+’asb’=null,   ’’+' asv’=' asv’

    取得長度: oracle :length()        SQL:len()

    取得部份字串: Oracle: substr(str,m,n)m為負從頭開始

                SQl   :     left(str,n) rigth(str,n) substring(str,m,n) m為負,傳回null

      取代:   replace(str1,str2,str3)

      大小寫: lower(),upper()

      刪除空白:ltrim(),rtrim(),oracle中要加from dual,SQL中不需要

    數值轉換成字串: Oracle  :  to_char()||’’

                  SQL :str()+’’

    NULL的值變換:

       Oracle: nvl(,0)    SQL :isnull( , )

    Update 的高階操作:

      Update tablename

      Set columns=(

                  Case

                      When columns<条件

                         Then columns*1.2

                      When columns >条件

                         Then  columns*1.5

                      Else  columns

                  end

    )

    Oracle  : decode 的使用:

                  select decode (字段,值1,值2,值3)  ‘’ new_column_name  from 表   如果字段=值1  则得到的结果是值2  否则得到的结果是值3

        Create  MySQL  rownum:         

     select distinct customer into #B2 from #B0

    select customer, identity(int,1,1)id into #B21

    from  #B2

    select * from #B21  order by id asc

    Oracle  NVL的使用:

        nvl( ,)是个函数,作用是如果第一个参数为空值,则返回第二个参数的值,否则返回第一个参数的值

  • 相关阅读:
    2019年春季第四周作业
    第三周作业
    第二周作业
    最大值及其下标
    查找整数
    PTA3
    币值转换
    三位老师
    自我介绍
    poj 3278 Catch That Cow(bfs)
  • 原文地址:https://www.cnblogs.com/alexzp/p/2302039.html
Copyright © 2011-2022 走看看