標籤:
一、運算子算術運算子:+ - * / 可以在select 語句中使用串連運算子:|| select deptno|| dname from dept; 比較子:> >= = != < <= like between is null in邏輯運算子:not and or 集合運算子: intersect ,union, union all, minus 要求:對應集合的列數和資料類型相同 查詢中不能包含long 列 列的標籤是第一個集合的標籤 使用order by時,必須使用位置序號,不能使用列名 1. 複製表結構及其資料: create table table_name_new as select * from table_name_old 2. 只複製表結構: create table table_name_new as select * from table_name_old where 1=2; 或者: create table table_name_new like table_name_old 3. 只複製表資料: 如果兩個表結構一樣: insert into table_name_new select * from table_name_old 如果兩個表結構不一樣: insert into table_name_new(column1,column2...) select column1,column2... from table_name_old pasting----------------------------------------------遞迴查詢--子查父(通過子節點向根節點追朔.) 查詢〔特下邊〕的父節點select * from tb_class t start with t.class_id = ‘1030107742‘connect by prior t.super_class_id = t.class_idorder by t.tree_level desc --父查子(通過根節點遍曆子節點.) 查詢〔特下邊〕的子節點:結果select * from tb_class t start with t.class_id = ‘1030107742‘connect by prior t.class_id = t.super_class_idorder by t.tree_level desc 1.NVL函數NVL函數的格式如下:NVL(expr1,expr2)含義是:如果oracle第一個參數為空白那麼顯示第二個參數的值,如果第一個參數的值不為空白,則顯示第一個參數本來的值。 oralce 坐串連右串連 有+號的表不全部顯示,對面的表全部顯示。 ----------------------------------------------2016-2-24 10:06:492、DECODE函數 ( )文法:decode(expr,search1,result1,search2,result2, ……search n,result n, default)解釋:decode函數將expr值與各search值一個一個比對,若expr值等於search值oracle資料庫返回其對應的result值;若沒有匹配的search值,則返回default值;若函數中default值預設則返回null。/*select decode(status,0,‘yes‘,1,‘no‘) as end from sys_user where id = 158 */ oracle進階update語句 (批量update)update t_source_phase p set p.lineno = (select num from t_source_line l where p.lineid = l.id) where p.lineid is not null; select的同時就update oracle進階查詢語句 (分組後按組排序) select t.*,row_number() over(partition by planid order by sort asc ) row_number from t_temp_pathinfo_log t
oracle增加欄位文法:@添加欄位的文法:alter table tablename add (column datatype [default value][null/not null],….); @修改欄位的文法:alter table tablename modify (column datatype [default value][null/not null],….); @刪除欄位的文法:alter table tablename drop (column);//2016年1月21日09:56:53@建立序列create sequence SEQ_DEPTminvalue 1maxvalue 99999999start with 241increment by 1cache 20; @進階語句 1.INSERT INTO SELECT --語句 語句形式為:Insert into Table2(field1,field2,...) select value1,value2,... from Table1 要求目標表Table2必須存在,由於目標表Table2已經存在,所以我們除了插入源表Table1的欄位外,還可以插入常量。 2.SELECT INTO FROM --語句 語句形式為:SELECT vale1, value2 into Table2 from Table1 要求目標表Table2不存在,因為在插入時會自動建立表Table2,並將Table1中指定欄位資料複製到Table2中。樣本如下:
oracle常用進階sql操作