標籤:acl for 返回 檢測 行列轉換 ace 記錄 number rom
刪 除 表:drop table 表名;改欄位名:alter table 表名 rename column 列名 to 新列名創 建 表:create table 表名(欄位名 欄位類型,欄位名);刪表資料:truncate table 表名; delete from 表名;增加欄位:alter table 表名 add(欄位名 varchar2(30)修改欄位類型: alter table tableName modify(columnName 類型); ps:alter table test modify(name varchar(255));oracle為應對大量的文本可以設定欄位類型為clob 查看具體的字元:select to_char(clob欄位) from table;1.rownum oracle每讀取到一行就給改行加一個編號。rownum是在查詢語句掃描每條記錄時產生的, 所以不能使用“大於”或“大於等於”符號,只能使用“小於”或“小於等於” 。(只用“等於”也不行) 2.求字串長度 length3.字串拼接concat4.字串替換replace select replace(‘adbcd‘ , ‘d‘,‘d‘) from dual5.求字串的子串substr6.四捨五入函數round 7.截取函數trunc 不會四捨五入8.加月函數 add_months :在當前日期基礎上加指定的月9.求所在月最後一天last_day 10.日期截取trunc 11.數字轉字串to_char12.日期轉字串to_char select to_char(sysdate,‘yyyy-mm-dd‘) from dual;13.字串轉數字to_number14.字串轉日期to_date select to_date(‘2018-03-09‘,‘yyyy-mm-dd‘) from dual;15.空值處理函數 nvl select nvl(null,0) from dual; select nvl2(檢測值,不為null的值,為null的值) from dual;16.條件取值 decode decode()函數:多數值判斷,類似於if…else語句,不同的是decode()判斷的是數值而不是邏輯條件 17.select (select name from t_area where id= areaid ) 地區, sum( case when month>=‘01‘ and month<=‘03‘ then money else 0 end) 第一季度, sum( case when month>=‘04‘ and month<=‘06‘ then money else 0 end) 第二季度, sum( case when month>=‘07‘ and month<=‘09‘ then money else 0 end) 第三季度, sum( case when month>=‘10‘ and month<=‘12‘ then money else 0 end) 第四季度 from t_account where year=‘2012‘ group by areaid 行列轉換18.union all(並集),返回各個查詢的所有記錄,包括重複記錄。 union(並集),返回各個查詢的所有記錄,不包括重複記錄。 intersect(交集),返回兩個查詢共有的記錄。 minus(差集),返回第一個查詢檢索出的記錄減去第二個查詢檢索出的記錄之後剩餘的記錄。 在使用連結查詢的時候需要返回的兩列有相同的列數。 19. declare v_num number:=1; 定義變數,定義迴圈初始值begin loop 開始迴圈dbms_output.put_line(v_num);v_num:=v_num+1; exit when v_num >100; 迴圈終止條件end loop;end; 20. begin for v_num in 1..200 for迴圈loop dbms_output.put_line(v_num); end loop;end;21.預存程序: create [ or replace ] procedure 預存程序名稱 (參數名 類型, 參數名 類型, 參數名 類型)is|as 變數聲明部分;begin 邏輯部分[exception 異常處理部分]end;22.call 預存程序名稱(參數); 在代碼中調用儲存函數23.得到星期一的日期select trunc(sysdate,‘‘DD‘‘)-to_char(sysdate,‘‘D‘‘)+2 from dual; --得到星期天的日期select trunc(sysdate,‘‘DD‘‘)-to_char(sysdate,‘‘D‘‘)+8 from dual;
Oracle常用命令集合