create or replace procedure proc_RatePhoto
(
procCompanyID in varchar2,
procBeginTime in date,
procEndTime in date
)
is
str varchar2(4000);
BEGIN
str:='CREATE temporary tablespace ls
(
companyID in varchar(200),
companyName in varchar(500),
All_Count in number default(0),
hege_Count in default(0)
)
On Commit Preserve Rows';
execute immediate str;
insert into ls (companyID,All_Count)
(select companyID,count(QualifiedFlag) as All_Count
from (select companyID,QualifiedFlag from View_PhotoInfo where UsedStop='0'and ControlTime between procBeginTime and procEndTime)
group by companyID);
insert into ls (companyID,hege_Count)
(select companyID,count(companyID) as hege_Count
from (select companyID,QualifiedFlag from View_PhotoInfo where UsedStop='0'and ControlTime between procBeginTime and procEndTime)
where QualifiedFlag='0'
group by companyID);
--更新单位名称。
update ls set ls.companyName=(selecT Data_CompanyInfo.CompanyName from Data_CompanyInfo where Data_CompanyInfo.CompanyID=ls.CompanyID)
where ls.CompanyID in(selecT CompanyID from Data_CompanyInfo);
--- UPDATE A SET A.NAME=(SELECT B.NAME FROM B WHERE B.ID=A.ID) WHERE A.ID IN (SELECT ID FROM B);
---得到合格率
select companyID,CompanyName,sum(All_Count) as All_Count,sum(hege_Count) as hege_Count
round( convert(float,sum(hege_Count))convert(float,sum(All_Count)),4)*100) as hegelv
from ls where companyID like '%' || procCompanyID|| '%'
group by companyID,CompanyName;
--drop table temp1
END;
------解决方案--------------------------------------------------------
BEGIN
str:='CREATE temporary tablespace ls
(
companyID in varchar(200),
companyName in varchar(500),
All_Count in number default(0),
hege_Count in default(0)
)
On Commit Preserve Rows';
execute immediate str;
commit; --------这里应该要显示提交。
insert into ls (companyID,All_Count)
(select companyID,count(QualifiedFlag) as All_Count
from (select companyID,QualifiedFlag from View_PhotoInfo where UsedStop='0'and ControlTime between procBeginTime and procEndTime)
group by companyID);
参考
http://www.cnblogs.com/goodbye305/archive/2008/06/23/1228073
2. 给动态语句传值(USING 子句)
declare
l_depnam varchar2(20) := 'testing';
l_loc varchar2(10) := 'Dubai';
begin
execute immediate 'insert into dept values (:1, :2, :3)'
using 50, l_depnam, l_loc;
commit;