oracle(3)select語句中常用的關鍵字說明


1.select 查詢表中的數據
  select
* from stu; ---查詢stu表所有的數據,*代表所有

2.dual ,偽表,要查詢的數據不存在任何表中時使用
  select sysdate from dual; ----查詢系統當前的時間
3.concat 連接兩個字符串為一個字符串
  select concat('孤舟蓑笠翁','獨釣寒江雪')str from dual; ---str為函數字段名(自取)
  等價操作:|| (連接符)
  select '莫等閑,'||'白了少年頭,'||'空悲切。' str from dual;
4.length 返回字符串的長度,單位是字符
   select length(name) from stu;

5.upper(大寫)、lower(小寫)、inicap(首字母大寫)
   select upper(upper),lower(LOWER),inicap(inicap) from dual;---UPPER/lower/Inicap


6.trim---去除兩邊重復的字符串:僅能截取一個字符
  ltrim---去除左邊重復的字符串:可以截取多個字符
  rtrim---去除右邊重復的字符串:可以截取多個字符
    select trim('n'from 'Come and go with every season') from dual;
    select ltrim('Come and go with every season','Con') from dual;---me and go with every season
     select rtrim('Come and go with every season','eason')from dual;---Come and go with every
7.substr 截取字符串 substr(char,start,length)
  select substr(name,1,2)from stu;
8.lpad / rpad 左、右補位
  select lpad(name,12,'*'),rpad(name,12,'*')from stu;將長度不足十二個字符的名字用(*)補位
9.instr(char1,char2[,n,m]) ---查找字符串char2在char1的位置,
                n:從char1的第幾個字符開始查找,m:char2字符第幾次出現,不寫都默認為1
  instr('instr','s') from dual; ---3
10.round(n[,m]):將數字n四舍五入,m為保留數字n小數點后第m位,不寫默認為0
   select round(55.555) from dual;---56
   select round(55.555,2) from dual;---55.56
   select round(55.555,-1)from dual;---60
11.trunc(n[,m]):直接截取數據,n、m同round的n、m
  select trunc(55.555,2) from dual;---55.55
12.ceil,floor :向上(下)取整,只有一個參數
  select ceil(55.55),floor(55.55) from dual;---56,55
13.mod(n,m) :返回n除以m后的余數
   select mod(14,5) from dual; ---4

14.date :日期類型,7個字節
  timestamp:日期類型,11個字節,可以存儲小數秒
  日期之間可以計算,返回的是天數

  YY 2位數的年     YYYY 4位數的年   MM 2位數的月    MON 簡拼的月
  MONTH 全拼的月   DD 2位數的天DY   周幾的縮寫   DAY 周幾的全拼
  HH24 24小時制的小時         HH12 12小時制的小時
  MI 顯示分      SS 顯示秒    AM 上下午

15.to_date:可以將給定的字符串轉換為date類型
   select to_date('2017-12-12 20:05:22','yyyy-mm-dd hh24:mi:ss')from dual;
16.to_char:可以將date按照固定的格式轉化為字符串
   select to_char(sysdate,'yyyy-mm-dd am hh24:mi:ss ') from dual;
17.last_day(date):返回給定日期當月的月底日期
18.add_months(data,i) : 返回給定日期加上i個月后的日期
19.months_between(date1,date2) :計數date1於date2之間相差多少月
20.extract() :提取給定日期的時間分量
  select extract(months from sysdate) from dual;
  select extract(second from systimestamp) from dual;
21.least/greatest 返回最小(大)值,可比較的類型有:數字,日期












  









 


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM