測試資料 zml

2022-06-06 11:57:08 字數 2785 閱讀 9315

---建立臨時表,插入測試資料--

create table #bom(母件 varchar(50),子件項次 varchar(100),子件 varchar (50),用量 numeric(16,4))

insert into #bom

select '10210100030','1','20012100008',1 union all

select '10210100030','2','20012110008',0.5 union all

select '10210100030','3','30300701001',1 union all

select '20012100008','1','2001210p161',1 union all

select '20012100008','2','30400201100',2 union all

select '20012110008','1','2001211s104',1 union all

select '20012110008','2','30400203000',0.5 union all

select '10210100026','1','20012100005',3 union all

select '10210100026','2','20012190012',4 union all

select '10210100026','3','30300201001',1 union all

select '20012100005','1','2001210p162',1 union all

select '20012100005','2','30400201100',0.5 union all

select '20012190012','1','2001219z001',2 union all

select '2001219z002','1','30400201111',2 union all

select '20012190012','2','2001219z002',2

--drop table #bom

--select * from #bom

---建立可多選函式---

create function splitin(@c varchar(2000),@split varchar(2))

returns @t table(col varchar(32))

as

begin

while(charindex(@split,@c)<>0)

begin

insert @t(col) values (substring(@c,1,charindex(@split,@c)-1))

set @c = stuff(@c,1,charindex(@split,@c),'')

end

insert @t(col) values (@c)

return

end

----建立展bom儲存過程---

create proc [dbo].[p_bom] @mmaster varchar(50)

asbegin

-----變數表--------

declare @bom table (序號 varchar(100),階次 varchar(10),層級 varchar(100),母件 varchar(50),子件 varchar(50),用量 numeric(16,4),實際用量 numeric(16,4))

;----遞規運算bom結構,結果插入表變數@bom-----

with t

as(

select le=convert(varchar(10),1),convert(varchar(100),子件項次) as 層級,*,實際用量=cast (用量 as numeric(16,4))

from #bom

where 母件 in (select col as 母件 from splitin(@mmaster,','))

union all

select le=convert(varchar(10),le+1),

convert(varchar(100),層級+','+convert(varchar(100),b.子件項次)) as 層級, ---bom子件項次合併,體現層級,用於排序體現bom結構

b.*,

cast(t.實際用量*b.用量 as numeric(16,4)) as 實際用量

from t

inner join #bom b on t.子件=b.母件

)insert into @bom select row_number() over(order by 層級) 序號,*

from

(select replicate('.',le)+ltrim(le)as 階次 ,---樹狀

層級,母件,子件,用量,實際用量

from t

union all

select distinct 階次= '0','0' as 層級,'' as 母件,母件 as 子件,用量=0,實際用量=0 ---頂層母件

from #bom as a

where a.母件 in (select col as 母件 from splitin(@mmaster,','))

)corder by c.層級

select * from @bom

endgo

exec p_bom'10210100030,10210100026'

構造測試資料 對比測試資料

正確 include using namespace std typedef long long ll const int max n 1e6 10 intmain return0 author max n date 2019 10 04 15.03.21 description 正確 錯誤 inc...

常用測試資料

程式或應用編寫好了之後,通常要輸入一些測試資料,我們懶人一般的做法就是,輸入 asdf,愛上對方,阿道夫。之類的隨手打的字元。這裡,我收集了一點點資料供測試時候使用,應該可以作為常用的測試資料。1.常用的姓名 平時,很多系統比如員工名字需要,但是又怕洩露隱私,所以這裡從網上收集了中國50個最常用的姓...

oracle training 測試資料

sqlplus sys zhou215 as sysdba startup connect oracle oracle 由於虛擬機器是linux的 plsql沒有linux的版本,需要通過本機連上虛擬機器 配置檢視ip sbin ifconfig a 192.168.81.128 將虛擬機器的ip填...