物料管理 两张表 递归(等待)
时间:2011-09-23
来源:互联网
bom1表结构
bom单号 物料
00001 水壶
00002 壶身
bom2表结构
bom单号 物料 使用量
00001 水壶盖 1
00001 壶身 3
00001 壶底 1
00002 铁皮 1
00002 螺丝 2
生成水壶 我需要:壶盖、壶底、螺丝、铁皮
怎么使用oracle的递归查出来
就是先看通过bom1的物料得到bom单号,再通过bom单号去bom2查物料,再将这个物料放到bom1中查看是否有bom单号,有的话再通过bom单号去bom2查物料……
我昨天写了一个不对只能查顶层一个,忘大家帮忙
create or replace function Fun_Bom(name in varchar) return number is
Result number;
id varchar2(20);
cursor my_cursor is
select 物料 from bom2 where bom单号 = id;
mat bom2.物料%type;
begin
select max(nvl(bom单号, '')) into id from bom1 where 物料=name;
if id is not null then
dbms_output.put_line(id);
open my_cursor;
loop
fetch my_cursor into mat;
DBMS_OUTPUT.PUT_LINE(mat);
return Fun_Bom(mat);
exit when my_cursor%notfound;
end loop;
close my_cursor;
end if;
return(0);
end Fun_Bom;
bom单号 物料
00001 水壶
00002 壶身
bom2表结构
bom单号 物料 使用量
00001 水壶盖 1
00001 壶身 3
00001 壶底 1
00002 铁皮 1
00002 螺丝 2
生成水壶 我需要:壶盖、壶底、螺丝、铁皮
怎么使用oracle的递归查出来
就是先看通过bom1的物料得到bom单号,再通过bom单号去bom2查物料,再将这个物料放到bom1中查看是否有bom单号,有的话再通过bom单号去bom2查物料……
我昨天写了一个不对只能查顶层一个,忘大家帮忙
create or replace function Fun_Bom(name in varchar) return number is
Result number;
id varchar2(20);
cursor my_cursor is
select 物料 from bom2 where bom单号 = id;
mat bom2.物料%type;
begin
select max(nvl(bom单号, '')) into id from bom1 where 物料=name;
if id is not null then
dbms_output.put_line(id);
open my_cursor;
loop
fetch my_cursor into mat;
DBMS_OUTPUT.PUT_LINE(mat);
return Fun_Bom(mat);
exit when my_cursor%notfound;
end loop;
close my_cursor;
end if;
return(0);
end Fun_Bom;
作者: one_in_one 发布时间: 2011-09-23
oracle的不熟 不过我给个SQL Server的思路吧
SQL code
SQL code
while @结果 = 1 begin if @需要查询的表 = 0 begin 在表一中查 set @结果 = @@rowcount set @需要查询的表 = 1; end else begin 在表二中查 set @结果 = @@rowcount set @需要查询的表 = 0; end end
作者: warrially 发布时间: 2011-09-23
谢谢!Oracle里的特有的函数我也不会用,我用的对多的也是SQL Server
作者: one_in_one 发布时间: 2011-09-23
相关阅读 更多
热门阅读
-
office 2019专业增强版最新2021版激活秘钥/序列号/激活码推荐 附激活工具
阅读:74
-
如何安装mysql8.0
阅读:31
-
Word快速设置标题样式步骤详解
阅读:28
-
20+道必知必会的Vue面试题(附答案解析)
阅读:37
-
HTML如何制作表单
阅读:22
-
百词斩可以改天数吗?当然可以,4个步骤轻松修改天数!
阅读:31
-
ET文件格式和XLS格式文件之间如何转化?
阅读:24
-
react和vue的区别及优缺点是什么
阅读:121
-
支付宝人脸识别如何关闭?
阅读:21
-
腾讯微云怎么修改照片或视频备份路径?
阅读:28