今天在網上看到乙個貼子,用一條語句,將資料同時插入多個表中,覺得很新奇,就自己練了一下,將語句記錄下來
step1:建立三個表,用於實驗測試:
create table t_table(object_id number, object_name varchar2(128), object_type varchar2(19));
create table t_index(object_id number, object_name varchar2(128), object_type varchar2(19));
create table t_view(object_id number, object_name varchar2(128), object_type varchar2(19));
step2:向三個表中插入資料
insert all
into t_table(object_id, object_name,object_type)
values(object_id, object_name,object_type)
into t_index(object_id, object_name,object_type)
values(object_id, object_name,object_type)
into t_view(object_id, object_name,object_type)
values(object_id, object_name,object_type)
select object_id, object_name,object_type
from dba_objects where object_type in('view','table','index');
step3:清空三張表,分類插入資料,即帶條件插入
truncate table t_table;
truncate table t_index;
truncate table t_view;
將資料分類插入
step4:清空三張,insert first,即帶條件插入insert all
when object_type='table' then
into t_table(object_id, object_name,object_type)
values(object_id, object_name,object_type)
when object_type='view' then
into t_index(object_id, object_name,object_type)
values(object_id, object_name,object_type)
else into t_view(object_id, object_name,object_type)
values(object_id, object_name,object_type)
select object_id, object_name, object_type
from dba_objects where object_type in ('view','table','index');
insert first
when object_id<1000 then
into t_table(object_id, object_name,object_type)
values(object_id, object_name,object_type)
when object_id>=1000 and object_id<2000 then
into t_index(object_id, object_name,object_type)
values(object_id, object_name,object_type)
else into t_view(object_id, object_name,object_type)
values(object_id, object_name,object_type)
select object_id, object_name, object_type
from dba_objects where object_type in ('view','table','index');
MySQL一條語句實現同時查詢和修改
mysql一條語句實現同時查詢和修改 現在想僅執行一條mysql語句得到 查詢到sid 2的使用者,然後修改gid的值為123。簡單這樣寫 1 update user set gid 123 whereidin selectidfrom user wheresid 2 肯定會報錯 錯誤碼 1093 ...
一條SQL語句研究
現有 select from t where a in 5,3,2,1,8,9,30.假設 a 是主鍵,in裡面的引數是唯一的。現要求輸出的結果集按照 in 提供的引數順序排序。而不是按照a本身的排序規則排序?另 如果不要求使用臨時表或表變數,那麼又有什麼辦法實現。臨時表方案參卡 create ta...
優化一條UPDATE語句
最近見到一條開發人員寫的update語句,覺得沒什麼不對,可又覺得有地方不對,因為效能低下.update a set col2,col3 select col1,t from b where b.col1 a.col1 where exists select b.col1 from b where ...