存儲過程插入檢索的數據
A. sql server 如何利用 存儲過程 建立一個新表,並向其中插入來自查詢的數據
直接insert into ... select ... 就行了。
例如,從A、B查詢結果,插入到C表:
insert into C(C1,C2)
select A.C1, B.C2 from A inner join B
on A.ID = B.ID
B. 建立一個存儲過程 需要把查到的數據插入到進去 並且判斷插入的數據是否存在 如果存在就不再插入。求語句
設表A(ID number),存儲過程如下:
create or replace procere P_insert(V_ID in number) as
i number:=0;
begin
select count(*) into i from A where ID=V_ID;
if i=0 then
insert into A values(V_ID);
end if;
commit;
end;
C. mysql存儲過程實現數據查詢與插入
INSERT into total_score_tmpD(
DepartmentNameEnd, StaffId,
StaffName,
CountPerHour,
SkillScoreDisCount ,
DealCount ,
ValueCount,
ValueCountDisCount
)
SELECT DepartmentName, StaffId,
StaffName,
3600/(Select DealAvgSeconds from deal_name_type where DealId='121300')*AVG(DealAvgSeconds/WaitSeconds) ,
Round(3600/(Select DealAvgSeconds from deal_name_type where DealId='121300')*avg(DealAvgSeconds/WaitSeconds)/(select Max(SunValue) From total_score_tmp33)*(select CAST(OptionValue as decimal) from sys_info WHERE OptionName='工作技能權重'),2),
count(StaffId),
Sum(DealValue),
Round(Sum(DealValue)/(select Max(SunValue) From total_score_tmp44)*(select CAST(OptionValue as decimal) from sys_info WHERE OptionName='工作效益權重'),2)
From deal_record
where DepartmentName like concat(DepartmentName2,'%') and DealDateTime BETWEEN STARTDealDateTime and endDealDateTime
group by StaffId;
insert into total_score_tmpc(DepartmentName , StaffId,
StaffName,
ClientNum ,
EvaluateScore ,
EvaluateScoreDisCount)
SELECT DepartmentName, StaffId,
StaffName,
count(StaffId),
Sum(EvaluatePrice),
Round((Sum(EvaluatePrice)/(select Max(SunValue) From total_score_tmp22))*(select CAST(OptionValue as decimal) from sys_info WHERE OptionName='服務評價權重'),2)
From evaluate_record
where DepartmentName like concat(DepartmentName2,'%') and EvaluateDateTime BETWEEN STARTDealDateTime and endDealDateTime
group by StaffId;
D. ORACLE存儲過程創建臨時表並插入數據。
存儲過程創建表後,在編譯階段資料庫中並沒有該表。這時向表中插入數據,會提示表不存在。所以,插入語句要賦值到變數里,通過e來執行。
E. 用oracle存儲過程將一張表的數據查出插入另一張表
1、創建測試表,
create table test_tbl_1(id number, value varchar2(20));
create table test_tbl_2(id number, value varchar2(20));
F. Oracle 存儲過程:如何將查詢到的數據插入到另一個用戶名下的一張表中
看你的這兩個用戶是不是在同一個資料庫中,如果不是同一個資料庫,可以建立一個DBLINK來連接;如果是在同意個庫內可以這樣寫:
insert into A(column1,column2,column3)
select bbb.B.columns1,bbb.B.columns2,bbb.B.columns3 from bbb.B
where bbb.B.columns1=0;