原来SQL SERVER 2000的存储过程
CREATE PROCEDURE up_analysisdraw
@gd varchar(10),
@rq varchar(10),
@num dec,
@stype int
asbegin transelect 任务分配表.制造工段 as zzcj,convert(char(7),任务分配表.zzjhrq,120) as zzjhrq,工序明细表.工序名称 as gxname,
sum(coalesce(工序明细表.单件定额 * 零件明细表.制件数量 ,0) )/60.0 as degs,'需求' as
into #tmp
from 工序明细表 (NOLOCK),任务分配表 (NOLOCK) ,零件明细表 (NOLOCK) ,b_加工工艺使用设备表
where 工序明细表.任务号 = 任务分配表.任务号 and
工序明细表.工装号 = 任务分配表.工装号 and
零件明细表.任务号 = 任务分配表.任务号 and
零件明细表.工装号 = 任务分配表.工装号 and
零件明细表.件号 = 工序明细表.件号 and
任务分配表.生产完工标识 = '0' and
工序明细表.wwbz= '0' and 工序明细表.单件定额>0 and 工序明细表.工序名称= b_加工工艺使用设备表.编号 and
ifusable='0' and b_加工工艺使用设备表.type <> '热表处理' and --hwgx is null and
case when 工序明细表.wwhm is null then 任务分配表.制造工段 else 工序明细表.wwhm end like @gd+'%' and 任务分配表.zzjh = '1' and
convert(char(7),任务分配表.zzjhrq,120) like @rq+'%'
group by 任务分配表.制造工段,convert(char(7),任务分配表.zzjhrq,120),工序明细表.工序名称 select a.工序名称 as gxname,coalesce(sum(operatorlist.degs)/60.0 ,0) as wcgs
into #tmp1
from operatorlist (NOLOCK),mom30100 (NOLOCK),mom30101 (NOLOCK),工序明细表 a (NOLOCK),任务分配表 b (NOLOCK)
where operatorlist.no = mom30101.no and operatorlist.seq = mom30101.seq and mom30101.no = mom30100.no and
a.任务号 = b.任务号 and a.工装号 = b.工装号 and
mom30100.rwh =a.任务号 and mom30100.gzh =a.工装号 and mom30100.jh =a.件号 and mom30100.gxh = a.工序号
and mom30100.type <>'2' and
b.生产完工标识 = '0' and a.wwbz= '0' and a.单件定额>0
and b.制造工段 like @gd+'%' --and a.工序名称 = 工序明细表.工序名称
and b.zzjh = '1' and convert(char(7),b.zzjhrq,120) like @rq+'%'
group by b.制造工段,convert(char(7),b.zzjhrq,120),a.工序名称
elect FDeptNumber as zzcj,@rq as zzjhrq,icdeviceofgx.gx as gxname,
(@num*t_equipworker.worktime *percent1/100) as hournum,isnull(dwhour,1.3) as dwhour ,'能力'as
into #tmp2
from ICDeviceAccount,icdeviceofgx,b_加工工艺使用设备表,t_equipworker
where ICDeviceAccount.FDeviceNumber = icdeviceofgx.fdevicenumber and
icdeviceofgx.fdevicenumber = t_equipworker.xh and
icdeviceofgx.gx = b_加工工艺使用设备表.编号
and ifusable='0' and b_加工工艺使用设备表.type <> '热表处理' and FDeptNumber like @gd+'%' and hwgx is null
order by gxname insert into #tmp2
(zzcj,zzjhrq,gxname,hournum,dwhour,)
SELECT icdeviceaddhour.cjgd,@rq as zzjhrq,icdeviceofgx.gx,
(DATEDIFF ( Day , icdeviceaddhour.sdt , icdeviceaddhour.edt ) + 1)* icdeviceaddhour.addhour as hournum,
isnull(icdeviceaddhour.dwhour,1.3) as dwhour , '能力'as
FROM icdeviceaddhour ,icdeviceofgx
WHERE icdeviceaddhour.FDeviceNumber =icdeviceofgx.fdevicenumber and
( icdeviceaddhour.cjgd like @gd+'%' ) and
( convert(char(7),icdeviceaddhour.sdt,120) = @rq ) and 1 = @stype insert into #tmp2
(zzcj,zzjhrq,gxname,hournum,dwhour,)
SELECT ICDeviceAccount.fdeptnumber,@rq as zzjhrq,icdeviceofgx.gx,
(isnull(ICDeviceMaintainPlan.hournum,0) *percent1*(-1)/100) as hournum,isnull(dwhour,1.3) as dwhour ,'能力'as
FROM ICDeviceMaintainPlan, ICDeviceAccount,icdeviceofgx,t_equipworker
WHERE ( ICDeviceMaintainPlan.fdevicenumber = ICDeviceAccount.FDeviceNumber ) and
ICDeviceAccount.FDeviceNumber =icdeviceofgx.fdevicenumber and
icdeviceofgx.fdevicenumber = t_equipworker.xh and
ICDeviceAccount.fdeptnumber like @gd+'%' and
convert(char(7), ICDeviceMaintainPlan.FPlanBeginDate,120) = @rq
--
select a.zzcj,
a.zzjhrq,
(select 工序内容 from b_加工工艺使用设备表 where 编号 = a.gxname) as gxname,
sum((case when a.degs - b.wcgs <0 then 0 else a.degs - b.wcgs end)) as ability,
from #tmp a,#tmp1 b
where a.gxname = b.gxname --需求
group by zzcj,zzjhrq,a.gxname,
union
select a.zzcj,
a.zzjhrq,
(select 工序内容 from b_加工工艺使用设备表 where 编号 = a.gxname) as gxname,
sum(a.hournum* a.dwhour) as ability,
from #tmp2 a
group by zzcj,zzjhrq,gxname,
drop table #tmp
drop table #tmp1
drop table #tmp2commit tran
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO想转为ORACLE9I数据库的 这个问题困扰我好几天了 因为刚接触ORACLE 以前用SQL SERVER 2000的 很多细节都过不去 希望高手指教下 越详细越好 我的问题 就出在临时表那块了 要详细说明啊
CREATE PROCEDURE up_analysisdraw
@gd varchar(10),
@rq varchar(10),
@num dec,
@stype int
asbegin transelect 任务分配表.制造工段 as zzcj,convert(char(7),任务分配表.zzjhrq,120) as zzjhrq,工序明细表.工序名称 as gxname,
sum(coalesce(工序明细表.单件定额 * 零件明细表.制件数量 ,0) )/60.0 as degs,'需求' as
into #tmp
from 工序明细表 (NOLOCK),任务分配表 (NOLOCK) ,零件明细表 (NOLOCK) ,b_加工工艺使用设备表
where 工序明细表.任务号 = 任务分配表.任务号 and
工序明细表.工装号 = 任务分配表.工装号 and
零件明细表.任务号 = 任务分配表.任务号 and
零件明细表.工装号 = 任务分配表.工装号 and
零件明细表.件号 = 工序明细表.件号 and
任务分配表.生产完工标识 = '0' and
工序明细表.wwbz= '0' and 工序明细表.单件定额>0 and 工序明细表.工序名称= b_加工工艺使用设备表.编号 and
ifusable='0' and b_加工工艺使用设备表.type <> '热表处理' and --hwgx is null and
case when 工序明细表.wwhm is null then 任务分配表.制造工段 else 工序明细表.wwhm end like @gd+'%' and 任务分配表.zzjh = '1' and
convert(char(7),任务分配表.zzjhrq,120) like @rq+'%'
group by 任务分配表.制造工段,convert(char(7),任务分配表.zzjhrq,120),工序明细表.工序名称 select a.工序名称 as gxname,coalesce(sum(operatorlist.degs)/60.0 ,0) as wcgs
into #tmp1
from operatorlist (NOLOCK),mom30100 (NOLOCK),mom30101 (NOLOCK),工序明细表 a (NOLOCK),任务分配表 b (NOLOCK)
where operatorlist.no = mom30101.no and operatorlist.seq = mom30101.seq and mom30101.no = mom30100.no and
a.任务号 = b.任务号 and a.工装号 = b.工装号 and
mom30100.rwh =a.任务号 and mom30100.gzh =a.工装号 and mom30100.jh =a.件号 and mom30100.gxh = a.工序号
and mom30100.type <>'2' and
b.生产完工标识 = '0' and a.wwbz= '0' and a.单件定额>0
and b.制造工段 like @gd+'%' --and a.工序名称 = 工序明细表.工序名称
and b.zzjh = '1' and convert(char(7),b.zzjhrq,120) like @rq+'%'
group by b.制造工段,convert(char(7),b.zzjhrq,120),a.工序名称
elect FDeptNumber as zzcj,@rq as zzjhrq,icdeviceofgx.gx as gxname,
(@num*t_equipworker.worktime *percent1/100) as hournum,isnull(dwhour,1.3) as dwhour ,'能力'as
into #tmp2
from ICDeviceAccount,icdeviceofgx,b_加工工艺使用设备表,t_equipworker
where ICDeviceAccount.FDeviceNumber = icdeviceofgx.fdevicenumber and
icdeviceofgx.fdevicenumber = t_equipworker.xh and
icdeviceofgx.gx = b_加工工艺使用设备表.编号
and ifusable='0' and b_加工工艺使用设备表.type <> '热表处理' and FDeptNumber like @gd+'%' and hwgx is null
order by gxname insert into #tmp2
(zzcj,zzjhrq,gxname,hournum,dwhour,)
SELECT icdeviceaddhour.cjgd,@rq as zzjhrq,icdeviceofgx.gx,
(DATEDIFF ( Day , icdeviceaddhour.sdt , icdeviceaddhour.edt ) + 1)* icdeviceaddhour.addhour as hournum,
isnull(icdeviceaddhour.dwhour,1.3) as dwhour , '能力'as
FROM icdeviceaddhour ,icdeviceofgx
WHERE icdeviceaddhour.FDeviceNumber =icdeviceofgx.fdevicenumber and
( icdeviceaddhour.cjgd like @gd+'%' ) and
( convert(char(7),icdeviceaddhour.sdt,120) = @rq ) and 1 = @stype insert into #tmp2
(zzcj,zzjhrq,gxname,hournum,dwhour,)
SELECT ICDeviceAccount.fdeptnumber,@rq as zzjhrq,icdeviceofgx.gx,
(isnull(ICDeviceMaintainPlan.hournum,0) *percent1*(-1)/100) as hournum,isnull(dwhour,1.3) as dwhour ,'能力'as
FROM ICDeviceMaintainPlan, ICDeviceAccount,icdeviceofgx,t_equipworker
WHERE ( ICDeviceMaintainPlan.fdevicenumber = ICDeviceAccount.FDeviceNumber ) and
ICDeviceAccount.FDeviceNumber =icdeviceofgx.fdevicenumber and
icdeviceofgx.fdevicenumber = t_equipworker.xh and
ICDeviceAccount.fdeptnumber like @gd+'%' and
convert(char(7), ICDeviceMaintainPlan.FPlanBeginDate,120) = @rq
--
select a.zzcj,
a.zzjhrq,
(select 工序内容 from b_加工工艺使用设备表 where 编号 = a.gxname) as gxname,
sum((case when a.degs - b.wcgs <0 then 0 else a.degs - b.wcgs end)) as ability,
from #tmp a,#tmp1 b
where a.gxname = b.gxname --需求
group by zzcj,zzjhrq,a.gxname,
union
select a.zzcj,
a.zzjhrq,
(select 工序内容 from b_加工工艺使用设备表 where 编号 = a.gxname) as gxname,
sum(a.hournum* a.dwhour) as ability,
from #tmp2 a
group by zzcj,zzjhrq,gxname,
drop table #tmp
drop table #tmp1
drop table #tmp2commit tran
GO
SET QUOTED_IDENTIFIER OFF
GO
SET ANSI_NULLS ON
GO想转为ORACLE9I数据库的 这个问题困扰我好几天了 因为刚接触ORACLE 以前用SQL SERVER 2000的 很多细节都过不去 希望高手指教下 越详细越好 我的问题 就出在临时表那块了 要详细说明啊
我现在做的方法是在太累了 基本是这样的CREATE OR REPLACE PROCEDURE "SYSTEM"."UP_ANALYSISDRAW" (gd
varchar2,rq varchar2,nums decimal,stype integer)
AS
str varchar2(4000);
v_num int;
begin
select count(*) into v_num from user_tables where table_name = 'tmp';
if v_num < 1 then
str := 'drop table tmp';
execute immediate str;
str := 'create global temporary table tmp
(
zzcj varchar2(20),
zzjhrq varchar2(20),
gxname varchar2(40),
degs decimal,
varchar2(20))
on commit preserve rows';
execute immediate str;
end if;
str :='insert into tmp (select 任务分配表.制造工段 as zzcj,to_char(任务分配表.zzjhrq,'||'''yyyy-mm'''||') as zzjhrq,工序明细表.工序名称 as gxname,
sum(nvl(工序明细表.单件定额 * 零件明细表.制件数量,0))/60.0 as degs,'||'''需求'''||' as from "SYSTEM"."工序明细表" , "SYSTEM"."任务分配表", "SYSTEM"."零件明细表", "SYSTEM"."b_加工工艺使用设备表"
where 工序明细表.任务号 = 任务分配表.任务号 and
工序明细表.工装号 = 任务分配表.工装号 and
零件明细表.任务号 = 任务分配表.任务号 and
零件明细表.工装号 = 任务分配表.工装号 and
零件明细表.件号 = 工序明细表.件号 and
任务分配表.生产完工标识 = '||'''0'''||' and
工序明细表.wwbz= '||'''0'''||' and 工序明细表.单件定额>0 and 工序明细表.工序名称= "SYSTEM"."b_加工工艺使用设备表".编号 and
ifusable='||'''0'''||' and "SYSTEM"."b_加工工艺使用设备表".type <> '||'''热表处理'''||' and
case when 工序明细表.wwhm is null then 任务分配表.制造工段 else 工序明细表.wwhm end like '||'''gd%'''||' and 任务分配表.zzjh = '||'''1'''||' and
to_char(任务分配表.zzjhrq,'||'''yyyy-mm'''||') like '||'''rq%'''||'
group by 任务分配表.制造工段,to_char(任务分配表.zzjhrq,'||'''yyyy-mm'''||'),工序明细表.工序名称) ';
execute immediate str;
-------------------------------------------------------------------------------------------------------------
--str := 'drop table tmp1';
--execute immediate str;
--str := 'create global temporary table tmp1
--(
--gxname varchar2(40),
--wcgs decimal
--)
--on commit preserve rows';
--execute immediate str;
--str := 'insert into tmp1 (select a.工序名称 as gxname,nvl(sum("SYSTEM"."operatorlist".degs)/60.0 ,0) as wcgs--from "SYSTEM"."operatorlist" ,"SYSTEM"."mom30100" ,"SYSTEM"."mom30101" ,"SYSTEM"."工序明细表" a ,
--"SYSTEM"."任务分配表" b
--where "SYSTEM"."operatorlist".no = "SYSTEM"."mom30101".no and "SYSTEM"."operatorlist".seq = "SYSTEM"."mom30101".seq and "SYSTEM"."mom30101".no = "SYSTEM"."mom30100".no and
--a.任务号 = b.任务号 and a.工装号 = b.工装号 and
--"SYSTEM"."mom30100".rwh =a.任务号 and "SYSTEM"."mom30100".gzh =a.工装号 and "SYSTEM"."mom30100".jh =a.件号 and "SYSTEM"."mom30100".gxh = a.工序号
--and "SYSTEM"."mom30100".type <>'||'''2'''||' and
-- b.生产完工标识 = '||'''0'''||' and a.wwbz= '||'''0'''||' and a.单件定额>0
--and b.制造工段 like '||'''gd%'''||'
--and b.zzjh = '||'''1'''||' and to_char(b.zzjhrq,'||'''yyyy-mm'''||') like '||'''rq%'''||'
--group by b.制造工段,to_char(b.zzjhrq,'||'''yyyy-mm'''||'),a.工序名称)';
--execute immediate str;
----------------------------------------------------------------------------------------------------------------------------
str := 'drop table tmp2';
execute immediate str;
str := 'create global temporary table tmp2
(
zzcj varchar2(20),
zzjhrq varchar2(20),
gxname varchar2(40),
hournum decimal,
dwhour decimal,
varchar2(20))
on commit preserve rows';
execute immediate str;
str :='insert into tmp2 (select "SYSTEM"."ICDeviceAccount".FDeptNumber as zzcj,rq as zzjhrq,"SYSTEM"."icdeviceofgx".gx as gxname,
(nums*"SYSTEM"."t_equipworker".worktime *percent1/100) as hournum,nvl(dwhour,1.3) as dwhour ,'||'''能力'''||'as from "SYSTEM"."ICDeviceAccount","SYSTEM"."icdeviceofgx","SYSTEM"."b_加工工艺使用设备表","SYSTEM"."t_equipworker"
where "SYSTEM"."ICDeviceAccount".FDeviceNumber = "SYSTEM"."icdeviceofgx".fdevicenumber and
"SYSTEM"."icdeviceofgx".fdevicenumber = "SYSTEM"."t_equipworker".xh and
"SYSTEM"."icdeviceofgx".gx = "SYSTEM"."b_加工工艺使用设备表".编号
and ifusable='||'''0'''||' and "SYSTEM"."b_加工工艺使用设备表".type <> '||'''热表处理'''||' and FDeptNumber like '||'''gd%'''||' and hwgx is null
) ';
execute immediate str;end;
这个东西累死了 尤其是拼接字符串那里 还有就是加表空间名字等等 有没有高手 帮我解决下啊
楼上不都说明白了么
--说的很详细了,存储过程里面不能每次都创建临时表,oracle与sqlserver不一样
http://blog.csdn.net/jsyzzcx/archive/2008/10/28/3164018.aspx
2 其他表都支持多用户查询 临时表也不例外
实在你这个问题不用贴代码 呵呵
‘建议你先建立好临时表,在存储过程里面每次调用时,先truncate table temptable一下,再操作数据’
像楼上说的 先清空数据最好 不过我刚才测试了 不同的登陆查询根本看不到对方的数据,即使同一个系统账户,我现在就想问 然后怎么写剩下的存储过程 我可以写脚本把用到的表先布在数据库里 难道非要这么写吗 str :='insert into tmp (select 任务分配表.制造工段 as zzcj,to_char(任务分配表.zzjhrq,'||'''yyyy-mm'''||') as zzjhrq,工序明细表.工序名称 as gxname,
sum(nvl(工序明细表.单件定额 * 零件明细表.制件数量,0))/60.0 as degs,'||'''需求'''||' as from "SYSTEM"."工序明细表" , "SYSTEM"."任务分配表", "SYSTEM"."零件明细表", "SYSTEM"."b_加工工艺使用设备表"
where 工序明细表.任务号 = 任务分配表.任务号 and
工序明细表.工装号 = 任务分配表.工装号 and
零件明细表.任务号 = 任务分配表.任务号 and
零件明细表.工装号 = 任务分配表.工装号 and
零件明细表.件号 = 工序明细表.件号 and
任务分配表.生产完工标识 = '||'''0'''||' and
工序明细表.wwbz= '||'''0'''||' and 工序明细表.单件定额>0 and 工序明细表.工序名称= "SYSTEM"."b_加工工艺使用设备表".编号 and
ifusable='||'''0'''||' and "SYSTEM"."b_加工工艺使用设备表".type <> '||'''热表处理'''||' and
case when 工序明细表.wwhm is null then 任务分配表.制造工段 else 工序明细表.wwhm end like '||'''gd%'''||' and 任务分配表.zzjh = '||'''1'''||' and
to_char(任务分配表.zzjhrq,'||'''yyyy-mm'''||') like '||'''rq%'''||'
group by 任务分配表.制造工段,to_char(任务分配表.zzjhrq,'||'''yyyy-mm'''||'),工序明细表.工序名称) ';
execute immediate str;这么写太累人了 测试也不好测试 有没有更好的办法处理 拼接字符串实在太累了 望解答。还有就是为什么我把存储过程建立到SYSTEM这个表空间下 我的数据表也都在SYSTEM这个表空间下 为什么用的时候还要加表空间名字 不加的话就提示“找不到这个表” SQL SERVER 2000 2个数据库之间查询 不就是加数据库前缀就可以吗 难道这个跟那个还不一样吗
感觉你sqlserver里 temporary table的概率和oracle不同
create global temporary table tmp
(
zzcj varchar2(20),
zzjhrq varchar2(20),
gxname varchar2(40),
degs decimal,
varchar2(20))
on commit delete rows; ------------------------------------------------------------------------------------------------------------------
create global temporary table tmp1
(
gxname varchar2(40),
wcgs decimal
)
on commit delete rows;
-----------------------------------------------------------------------------------------------------------------
create global temporary table tmp2
(
zzcj varchar2(20),
zzjhrq varchar2(20),
gxname varchar2(40),
hournum decimal,
dwhour decimal,
varchar2(20))
on commit DELETE rows
----------------------------------------------------------------------------------------------------------------
--这是ORACLE存储过程
CREATE OR REPLACE PROCEDURE "SYSTEM"."UP_ANALYSISDRAW" (gd
varchar2,rq varchar2,nums decimal,stype integer,RESULTSET OUT TEST_PAK.TESTRESULTSET)
ASbegin
insert into tmp (select 任务分配表.制造工段 as zzcj,to_char(任务分配表.zzjhrq,'yyyy-mm') as zzjhrq,工序明细表.工序名称 as gxname,
sum(coalesce(工序明细表.单件定额 * 零件明细表.制件数量 ,0) )/60.0 as degs,'需求' as
from "SYSTEM".工序明细表,"SYSTEM".任务分配表,"SYSTEM".零件明细表,"SYSTEM"."b_加工工艺使用设备表"
where 工序明细表.任务号 = 任务分配表.任务号 and
工序明细表.工装号 = 任务分配表.工装号 and
零件明细表.任务号 = 任务分配表.任务号 and
零件明细表.工装号 = 任务分配表.工装号 and
零件明细表.件号 = 工序明细表.件号 and
任务分配表.生产完工标识 = '0' and
工序明细表.wwbz= '0' and 工序明细表.单件定额>0 and 工序明细表.工序名称= "SYSTEM"."b_加工工艺使用设备表".编号 and
ifusable='0' and "SYSTEM"."b_加工工艺使用设备表".type <> '热表处理' and
case when 工序明细表.wwhm is null then 任务分配表.制造工段 else 工序明细表.wwhm end like gd||'%' and 任务分配表.zzjh = '1' and
to_char(任务分配表.zzjhrq,'yyyy-mm') like rq||'%'
group by 任务分配表.制造工段,to_char(任务分配表.zzjhrq,'yyyy-mm'),工序明细表.工序名称);-------------------------------------------------------------------------------------------------------------
insert into tmp1 (select a.工序名称 as gxname,coalesce(sum("SYSTEM"."operatorlist".degs)/60.0 ,0) as wcgsfrom "SYSTEM"."operatorlist" ,"SYSTEM"."mom30100" ,"SYSTEM"."mom30101","SYSTEM"."工序明细表" a,"SYSTEM"."任务分配表" b
where "SYSTEM"."operatorlist".no = "SYSTEM"."mom30101".no and "SYSTEM"."operatorlist".seq = "SYSTEM"."mom30101".seq and "SYSTEM"."mom30101".no = "SYSTEM"."mom30100".no and
a.任务号 = b.任务号 and a.工装号 = b.工装号 and
"SYSTEM"."mom30100".rwh =a.任务号 and "SYSTEM"."mom30100".gzh =a.工装号 and "SYSTEM"."mom30100".jh =a.件号 and "SYSTEM"."mom30100".gxh = a.工序号
and "SYSTEM"."mom30100".type <>'2' and
b.生产完工标识 = '0' and a.wwbz= '0' and a.单件定额>0
and b.制造工段 like gd||'%'
and b.zzjh = '1' and to_char(b.zzjhrq,'yyyy-mm') like rq||'%'
group by b.制造工段,to_char(b.zzjhrq,'yyyy-mm'),a.工序名称);
-------------------------------------------------------------------------------------------------------------------------
--下面是能力:
--标准能力(含倒班)
insert into tmp2 select FDeptNumber as zzcj,rq as zzjhrq,"SYSTEM"."icdeviceofgx".gx as gxname,
(nums*"SYSTEM"."t_equipworker".worktime *percent1/100) as hournum,NVL(dwhour,1.3) as dwhour ,'能力'as
from "SYSTEM"."ICDeviceAccount","SYSTEM"."icdeviceofgx","SYSTEM"."b_加工工艺使用设备表","SYSTEM"."t_equipworker"
where "SYSTEM"."ICDeviceAccount".FDeviceNumber = "SYSTEM"."icdeviceofgx".fdevicenumber and
"SYSTEM"."icdeviceofgx".fdevicenumber = "SYSTEM"."t_equipworker".xh and
"SYSTEM"."icdeviceofgx".gx = "SYSTEM"."b_加工工艺使用设备表".编号
and ifusable='0' and "SYSTEM"."b_加工工艺使用设备表".type <> '热表处理' and FDeptNumber like gd||'%' and hwgx is null
order by gxname;
---------------------------------------------------------------------------------------------------------------- 加班 ,注:在加班输入时不能跨越
insert into tmp2
(zzcj,zzjhrq,gxname,hournum,dwhour,)
SELECT "SYSTEM"."icdeviceaddhour".cjgd,rq as zzjhrq,"SYSTEM"."icdeviceofgx".gx,
ABS(ROUND(TO_NUMBER("SYSTEM"."icdeviceaddhour".sdt , "SYSTEM"."icdeviceaddhour".edt) + 1))* "SYSTEM"."icdeviceaddhour".addhour as hournum,
NVL("SYSTEM"."icdeviceaddhour".dwhour,1.3) as dwhour , '能力'as
FROM "SYSTEM"."icdeviceaddhour" ,"SYSTEM"."icdeviceofgx"
WHERE "SYSTEM"."icdeviceaddhour".FDeviceNumber ="SYSTEM"."icdeviceofgx".fdevicenumber and
( "SYSTEM"."icdeviceaddhour".cjgd like gd||'%' ) and
( to_char("SYSTEM"."icdeviceaddhour".sdt,'yyyy-mm') = rq ) and 1 = stype;
----------------------------------------------------------------------------------------------------------------------
--保养计划时间
insert into tmp2
(zzcj,zzjhrq,gxname,hournum,dwhour,)
SELECT "SYSTEM"."ICDeviceAccount".fdeptnumber,rq as zzjhrq,"SYSTEM"."icdeviceofgx".gx,
(NVL("SYSTEM"."ICDeviceMaintainPlan".hournum,0) *percent1*(-1)/100) as hournum,NVL(dwhour,1.3) as dwhour ,'能力'as
FROM "SYSTEM"."ICDeviceMaintainPlan","SYSTEM"."ICDeviceAccount","SYSTEM"."icdeviceofgx","SYSTEM"."t_equipworker"
WHERE ( "SYSTEM"."ICDeviceMaintainPlan".fdevicenumber = "SYSTEM"."ICDeviceAccount".FDeviceNumber ) and
"SYSTEM"."ICDeviceAccount".FDeviceNumber ="SYSTEM"."icdeviceofgx".fdevicenumber and
"SYSTEM"."icdeviceofgx".fdevicenumber = "SYSTEM"."t_equipworker".xh and
"SYSTEM"."ICDeviceAccount".fdeptnumber like gd||'%' and
to_char("SYSTEM"."ICDeviceMaintainPlan".FPlanBeginDate,'yyyy-mm') = rq ;
---------------------------------------------------------------------------------------------------------------------
OPEN RESULTSET FOR
select a.zzcj,a.zzjhrq,
(select 工序内容 from "SYSTEM"."b_加工工艺使用设备表" where 编号 = a.gxname) as gxname,
sum((case when a.degs - b.wcgs <0 then 0 else a.degs - b.wcgs end)) as ability,
from tmp a,tmp1 b
where a.gxname = b.gxname --需求
group by zzcj,zzjhrq,a.gxname,
union
select a.zzcj,
a.zzjhrq,
(select 工序内容 from "SYSTEM"."b_加工工艺使用设备表" where 编号 = a.gxname) as gxname,
sum(a.hournum* a.dwhour) as ability,
from tmp2 a
group by zzcj,zzjhrq,gxname,;
COMMIT;
end;
----------------------------------------------------------------------------------
/*创建程序包头与程序包体*/
create or replace package "SYSTEM".test_pak is
type testresultset is ref cursor;
end test_pak;
--------------------------------------------------------------------------------------------------
上面就是建立这个存储过程用到的 下面是测试数据的在PL/SQL里面declare gd varchar(20);
rq varchar(20);
nums decimal;
stype integer;
dsfs TEST_PAK.TESTRESULTSET;
begin
gd:= '048';
rq := '2010-01';
nums :=1;
stype := 1;
system.up_analysisdraw(gd ,
rq ,
nums ,
stype ,
dsfs);
end;我现在就是不知道怎么能把数据查出来 执行也没问题 可是就是看不到数据 不知道问题出在哪了
2。( "SYSTEM"."icdeviceaddhour".cjgd like gd||'%' ) and
3。to_char(任务分配表.zzjhrq,'yyyy-mm') like rq||'%'
4。 to_char("SYSTEM"."icdeviceaddhour".sdt,'yyyy-mm') = rq ) and 1 = stype
这上面的NUMS,gd,rq,stype都是存储过程参数 这么用是不是不对啊 可我在ORACLE里面可以编译过去 在PL/SQL里面执行 也能成功 问题是看不都数据
最后记得commit一下,oracle数据库默认不提交,需要自己手工去commit
select a.zzcj,a.zzjhrq,
(select 工序内容 from "SYSTEM"."b_加工工艺使用设备表" where 编号 = a.gxname) as gxname,
sum((case when a.degs - b.wcgs <0 then 0 else a.degs - b.wcgs end)) as ability,
from tmp a,tmp1 b
where a.gxname = b.gxname --需求
group by zzcj,zzjhrq,a.gxname,
union
select a.zzcj,
a.zzjhrq,
(select 工序内容 from "SYSTEM"."b_加工工艺使用设备表" where 编号 = a.gxname) as gxname,
sum(a.hournum* a.dwhour) as ability,
from tmp2 a
group by zzcj,zzjhrq,gxname,;
COMMIT;
我建立的是事物级的临时表 最后查询提交了啊 如果每次INSERT都提交 那就差不出数据了 我的意思是不是我哪写错了 你帮我看看返回数据集那块是不是有问题 就是建立程序包头那里 是不是还需要建立个程序包体
sql>var x refcursor;
sql>exec MENURIGHT('user_code', :x);
sql>print :x; 正确,但要在sqlplus下.我用的这种模式 打印出数据了 而且是正确的 我想问下 如果在PL/SQL里面 想得到数据集 我要怎么写
declare gd varchar(20);
rq varchar(20);
nums decimal;
stype integer;
dsfs TEST_PAK.TESTRESULTSET;
begin
gd:= '048';
rq := '2010-01';
nums :=1;
stype := 1;
system.up_analysisdraw(gd ,
rq ,
nums ,
stype ,
dsfs);
end;
这么写肯定不对了 有没有人帮我改正下
不要再存储过程里面写SQL语句,没有什么意义,还需要用游标去取数据,很麻烦