insertintoempvalues(1234,'LIZELU','BOSS',1234,'1980-12-06',10000.0,0,30);insertintoempvalues(1234,'LIZELU','BOSS',1234,'1980-12-06',10000.0,0,30)ORA-01861:文字與格式字符串不匹配--日期格式不對使用to_date()" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Oracle 常用函數(shù)

系統(tǒng) 1957 0

1.Oracle 數(shù)據(jù)庫中的to_date()函數(shù)的使用:   往emp表中插入一條記錄:

      SQL
      
        > 
        
          insert 
          
            into emp 
            
              values(
              
                1234,
                
                  '
                  
                    LIZELU
                    
                      ',
                      
                        '
                        
                          BOSS
                          
                            ',
                            
                              1234,
                              
                                '
                                
                                  1980-12-06
                                  
                                    ',
                                    
                                      10000.0,
                                      
                                        0,
                                        
                                          30
                                          
                                            ); 
                                            
                                              insert 
                                              
                                                into emp 
                                                
                                                  values(
                                                  
                                                    1234,
                                                    
                                                      '
                                                      
                                                        LIZELU
                                                        
                                                          ',
                                                          
                                                            '
                                                            
                                                              BOSS
                                                              
                                                                ',
                                                                
                                                                  1234,
                                                                  
                                                                    '
                                                                    
                                                                      1980-12-06
                                                                      
                                                                        ',
                                                                        
                                                                          10000.0,
                                                                          
                                                                            0,
                                                                            
                                                                              30
                                                                              
                                                                                ) ORA
                                                                                
                                                                                  -
                                                                                  
                                                                                    01861: 文字與格式字符串不匹配
                                                                                    
                                                                                      --
                                                                                      
                                                                                        日期格式不對 
                                                                                        
                                                                                           使用to_date()函數(shù)搞定:格式to_date(
                                                                                          
                                                                                            '
                                                                                            
                                                                                              1965-02-05
                                                                                              
                                                                                                ',
                                                                                                
                                                                                                  '
                                                                                                  
                                                                                                    yyyy-mm-dd
                                                                                                    
                                                                                                      '); 
                                                                                                    
                                                                                                  
                                                                                                
                                                                                              
                                                                                            
                                                                                          
                                                                                        
                                                                                      
                                                                                    
                                                                                  
                                                                                
                                                                              
                                                                            
                                                                          
                                                                        
                                                                      
                                                                    
                                                                  
                                                                
                                                              
                                                            
                                                          
                                                        
                                                      
                                                    
                                                  
                                                
                                              
                                            
                                          
                                        
                                      
                                    
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

?

2.Oracle中的字符函數(shù):

  字符函數(shù)是Oracle中最常用的函數(shù),   lower(char); 把字符串轉(zhuǎn)換為小寫格式;   upper(char);把字符串轉(zhuǎn)換為大寫格式;   length(char);返回字符串的長度;   substr(char,m,n);取字符串的字串;   replace(char,search_char,replace_str);

  1.將所有員工的名字按小寫的格式輸出

      
        select 
        
          lower(emp.ename) 
          
            from emp;
          
        
      
    

  2.顯示正好為5個字符的名字;

      
        select ename 
        
          from emp 
          
            where length(ename)
            
              =
              
                5;
              
            
          
        
      
    

  3.顯示姓名的前三個字符;substr(char,2,3);代表從第二個取,取三個字符;

      
        select substr(ename,
        
          1,
          
            3) 
            
              from emp;
            
          
        
      
    

  4.顯示姓名要求首字母大寫,其余的小寫;     分成三部走:     (1)把首字母大寫:

      
        select 
        
          upper(substr(emp.ename,
          
            1,
            
              1)) 
              
                from emp;
              
            
          
        
      
    

    (2)把后面的字母小寫:

      
        select 
        
          lower(substr(ename,
          
            2,length(ename)
            
              -
              
                1)) 
                
                  from emp;
                
              
            
          
        
      
    

    (3)把兩個字符串連接起來 ||(管道符是連接作用的)

      
        select 
        
          upper(substr(emp.ename,
          
            1,
            
              1))
              
                ||
                
                  lower(substr(ename,
                  
                    2,length(ename)
                    
                      -
                      
                        1)) 
                        
                          from emp;
                        
                      
                    
                  
                
              
            
          
        
      
    

?

?

  5.把名字中的A轉(zhuǎn)換為a;

      
        select 
        
          replace(ename,
          
            '
            
              A
              
                ',
                
                  '
                  
                    a
                    
                      ') 
                      
                        from emp;
                      
                    
                  
                
              
            
          
        
      
    

?

3.Oracle 中的數(shù)學(xué)函數(shù):   1.round(n,[m]):四舍五入,省略m則四舍五入到整數(shù)位,m為小數(shù)點的位數(shù);

      
        select 
        
          round(sal,
          
            1) 
            
              from emp 
              
                where ename
                
                  =
                  
                    '
                    
                      MILLER
                      
                        ';
                      
                    
                  
                
              
            
          
        
      
    

  2.trunc(n,[m]):保留小數(shù)位,m為小數(shù)位的個數(shù)

      
        select trunc(sal,
        
          1) 
          
            from emp 
            
              where ename
              
                =
                
                  '
                  
                    MILLER
                    
                      ';
                    
                  
                
              
            
          
        
      
    

  3.mod(n,m):去小數(shù);
  4.floor(n):返回小于等于n的最大整數(shù);? ceil(n):返回大于等于n的最小整數(shù)

      SQL
      
        > 
        
          select 
          
            floor(sal) 
            
              from emp 
              
                where ename
                
                  =
                  
                    '
                    
                      MILLER
                      
                        ';
                        
                          --
                          
                            向下取整 
                            
                              FLOOR
                              
                                (SAL) 
                                
                                  --
                                  
                                    -------- 
                                    
                                      1300
                                      
                                         SQL
                                        
                                          > 
                                          
                                            select ceil(sal) 
                                            
                                              from emp 
                                              
                                                where ename
                                                
                                                  =
                                                  
                                                    '
                                                    
                                                      MILLER
                                                      
                                                        ';
                                                        
                                                          --
                                                          
                                                            向上取整 
                                                            
                                                               CEIL(SAL) 
                                                              
                                                                --
                                                                
                                                                  -------- 
                                                                  
                                                                    1301
                                                                  
                                                                
                                                              
                                                            
                                                          
                                                        
                                                      
                                                    
                                                  
                                                
                                              
                                            
                                          
                                        
                                      
                                    
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

其他數(shù)學(xué)函數(shù): abs(n):返回數(shù)字n的絕對值。 acos(n),asin(n),stan(n) 返回數(shù)字的反余弦,反正弦,反正切的值 exp(n):返回e的n次冪; log(m,n);返回對數(shù)值; power(m,n);返回m的n次冪

?

4.Oracle中的日期函數(shù):   日期函數(shù)用于處理date類型的數(shù)據(jù):默認(rèn)情況下是dd-mon-yy格式。   (1)sysdate:該函數(shù)返回系統(tǒng)時間

      SQL
      
        > 
        
          select sysdate 
          
            from
            
               dual; SYSDATE 
              
                --
                
                  --------- 
                  
                    2014
                    
                      -
                      
                        4
                        
                          -
                          
                            13 
                            
                              9
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

 ?。?)add_moths(d,n);

    顯示入職8個多月的職工;

      
        select 
        
          * 
          
            from emp 
            
              where sysdate
              
                >add_months(emp.hiredate,
                
                  8);
                
              
            
          
        
      
    

?

  (3)last_day(d);返回當(dāng)前日期該月的最后一天

      
        select last_day(emp.hiredate) 
        
          from emp;
        
      
    

?

 ( 4)顯示員入職的天數(shù)

      SQL
      
        > 
        
          select ename,
          
            round(sysdate
            
              -emp.hiredate) "入職天數(shù)" 
              
                from emp;
              
            
          
        
      
    

?

  (5) 找出個月的倒數(shù)第3天入職的員工

      SQL
      
        > 
        
          select 
          
            * 
            
              from emp 
              
                where (last_day(emp.hiredate)
                
                  -emp.hiredate)
                  
                    =
                    
                      2;
                    
                  
                
              
            
          
        
      
    

?

?

?

?

5.Oracle中數(shù)據(jù)類型的轉(zhuǎn)換   to_char():把數(shù)據(jù)轉(zhuǎn)換為字符串類型:to_char(字符串,類型);

  1.日期轉(zhuǎn)換

      SQL
      
        > 
        
          select to_char(sysdate,
          
            '
            
              yyyy/mm/dd hh24:mi:ss
              
                ') 
                
                  from
                  
                     dual; TO_CHAR(SYSDATE,
                    
                      '
                      
                        YYYY/MM/DDHH2 ------------------------------ 2014/04/13 10:13:52
                      
                    
                  
                
              
            
          
        
      
    

  2.顯示1980年入職的員工信息

      SQL
      
        > 
        
          select 
          
            * 
            
              from emp 
              
                where to_char(emp.hiredate,
                
                  '
                  
                    yyyy
                    
                      ')
                      
                        =
                        
                          1980
                          
                            ; EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO 
                            
                              --
                              
                                --- ---------- --------- ----- ----------- --------- --------- ------ 
                                
                                  1234 LIZELU BOSS 
                                  
                                    1234 
                                    
                                      1980
                                      
                                        -
                                        
                                          12
                                          
                                            -
                                            
                                              6 
                                              
                                                10000.00 
                                                
                                                  0.00 
                                                  
                                                    30 
                                                    
                                                      7369 SMITH CLERK 
                                                      
                                                        7902 
                                                        
                                                          1980
                                                          
                                                            -
                                                            
                                                              12
                                                              
                                                                -
                                                                
                                                                  17 
                                                                  
                                                                    800.00 
                                                                    
                                                                      20
                                                                    
                                                                  
                                                                
                                                              
                                                            
                                                          
                                                        
                                                      
                                                    
                                                  
                                                
                                              
                                            
                                          
                                        
                                      
                                    
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

?

6.Oracle中的系統(tǒng)函數(shù):sys_context();   1) terminal 當(dāng)前會話客戶所對應(yīng)的終端標(biāo)識符

      SQL
      
        > 
        
          select sys_context(
          
            '
            
              USERENV
              
                ',
                
                  '
                  
                    terminal
                    
                      ') 
                      
                        from
                        
                           dual; SYS_CONTEXT(
                          
                            '
                            
                              USERENV
                              
                                ',
                                
                                  '
                                  
                                    TERMINA -------------------------------------------------------------------------------- WEB-A93B1E61669
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

  2) language 語言

      SQL
      
        > 
        
          select sys_context(
          
            '
            
              USERENV
              
                ',
                
                  '
                  
                    language
                    
                      ') 
                      
                        from
                        
                           dual; SYS_CONTEXT(
                          
                            '
                            
                              USERENV
                              
                                ',
                                
                                  '
                                  
                                    LANGUAG -------------------------------------------------------------------------------- SIMPLIFIED CHINESE_CHINA.ZHS16GBK
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

?

  3)db_name 當(dāng)前的數(shù)據(jù)庫實例名稱

      SQL
      
        > 
        
          select sys_context(
          
            '
            
              USERENV
              
                ',
                
                  '
                  
                    db_name
                    
                      ') 
                      
                        from
                        
                           dual; SYS_CONTEXT(
                          
                            '
                            
                              USERENV
                              
                                ',
                                
                                  '
                                  
                                    DB_NAME -------------------------------------------------------------------------------- orcl
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

?

  4)session_user 當(dāng)前會話所對應(yīng)的數(shù)據(jù)庫

      SQL
      
        > 
        
          select sys_context(
          
            '
            
              USERENV
              
                ',
                
                  '
                  
                    session_user
                    
                      ') 
                      
                        from
                        
                           dual; SYS_CONTEXT(
                          
                            '
                            
                              USERENV
                              
                                ',
                                
                                  '
                                  
                                    SESSION -------------------------------------------------------------------------------- SCOTT
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

?

  5)current_schema:查看當(dāng)前方案

      SQL
      
        > 
        
          select sys_context(
          
            '
            
              USERENV
              
                ',
                
                  '
                  
                    current_schema
                    
                      ') 
                      
                        from
                        
                           dual; SYS_CONTEXT(
                          
                            '
                            
                              USERENV
                              
                                ',
                                
                                  '
                                  
                                    CURRENT -------------------------------------------------------------------------------- SCOTT
                                  
                                
                              
                            
                          
                        
                      
                    
                  
                
              
            
          
        
      
    

Oracle 常用函數(shù)


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號聯(lián)系: 360901061

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點擊下面給點支持吧,站長非常感激您!手機(jī)微信長按不能支付解決辦法:請將微信支付二維碼保存到相冊,切換到微信,然后點擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對您有幫助就好】

您的支持是博主寫作最大的動力,如果您喜歡我的文章,感覺我的文章對您有幫助,請用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長會非常 感謝您的哦!!!

發(fā)表我的評論
最新評論 總共0條評論
主站蜘蛛池模板: 东至县| 襄城县| 乐至县| 定边县| 衡南县| 左贡县| 大连市| 新巴尔虎右旗| 新绛县| 始兴县| 延川县| 龙门县| 青州市| 定西市| 郧西县| 外汇| 太保市| 诸暨市| 凉山| 肥城市| 中江县| 外汇| 成安县| 保德县| 兰考县| 潮安县| 青阳县| 曲阳县| 敦化市| 凌海市| 金寨县| 福清市| 敦化市| 革吉县| 兴业县| 呼玛县| 台中县| 始兴县| 基隆市| 卓尼县| 诸城市|