3

Sql Server转换Orcale

CREATE TABLE [dbo].Table_1 NULL, [Material] nvarchar NULL, [Projects] nvarchar NULL, [Calculate] nvarchar NULL, [Datass] nvarchar NULL, [Formula] nvarchar NULL, [Tolerance] nvarchar NULL, [Standard] nvarchar NULL) ON [PRIMARY]GOINSERT INTO [Table_1] VALUES (1, '硫酸亚铁_含量', '质量', '否', 10, '', '', '');INSERT INTO [Table_1] VALUES (2, '硫酸亚铁_含量', '体积', '否', 20, '', '', '');INSERT INTO [Table_1] VALUES (3, '硫酸亚铁_含量', '标液', '否', 30, '', '', '');INSERT INTO [Table_1] VALUES (4, '硫酸亚铁_含量', '含量', '是', '', ' 体积*标液*0.27801/质量', '≤0.4%', '');INSERT INTO [Table_1] VALUES (5, '硫酸亚铁_二氧化钛', '质量1', '否', 0.25, '', '', '');INSERT INTO [Table_1] VALUES (6, '硫酸亚铁_二氧化钛', '质量2', '否', 0.35, '', '', '');INSERT INTO [Table_1] VALUES (7, '硫酸亚铁_二氧化钛', 'm', '否', 0.45, '', '', '');INSERT INTO [Table_1] VALUES (8, '硫酸亚铁_二氧化钛', '含量', '是', '', '5*m/质量1', '≤0.02%', '');INSERT INTO [Table_1] VALUES (9, '硫酸亚铁_水不溶物', '质量1', '否', 0.11, '', '', '');INSERT INTO [Table_1] VALUES (10, '硫酸亚铁_水不溶物', 'm1', '否', 0.66, '', '', '');INSERT INTO [Table_1] VALUES (11, '硫酸亚铁_水不溶物', 'm2', '否', 0.88, '', '', '');INSERT INTO [Table_1] VALUES (12, '硫酸亚铁_水不溶物', '含量', '是', '', '(m2-m1)/质量1', '≤0.04%', '');INSERT INTO [Table_1] VALUES (13, '烧碱', '质量', '否', 0.99, '', '', '');INSERT INTO [Table_1] VALUES (14, '烧碱', '体积', '否', 0.44, '', '', '');INSERT INTO [Table_1] VALUES (15, '烧碱', '标液', '否', 11.5, '', '', '');INSERT INTO [Table_1] VALUES (16, '烧碱', '含量', '是', '', '体积*标液*0.8/质量', '≤0.1%', '≥30.0%');INSERT INTO [Table_1] VALUES (17, '双氧水_含量', '质量', '否', 1.56, '', '', '');INSERT INTO [Table_1] VALUES (18, '双氧水_含量', '体积', '否', 1.913, '', '', '');INSERT INTO [Table_1] VALUES (19, '双氧水_含量', '标液', '否', 1.55, '', '', '');INSERT INTO [Table_1] VALUES (20, null, null, null, null, null, null, null);DECLARE @Material VARCHAR(20),@Projects VARCHAR(20),@Datass NUMERIC(6,4),@Formula VARCHAR(50),@Sql VARCHAR(50)DECLARE my_cur1 CURSOR FOR --读取Material的公式SELECT Material FROM Table_1 WHERE Calculate='是'OPEN my_cur1FETCH NEXT FROM my_cur1 INTO @MaterialWHILE @@FETCH_STATUS=0BEGINSELECT @Formula = Formula FROM Table_1 WHERE Material=@MaterialDECLARE my_cur2 CURSOR FOR --读取ProjectSELECT Projects FROM Table_1 WHERE Material=@Material AND Calculate<>'是'OPEN my_cur2FETCH NEXT FROM my_cur2 INTO @ProjectsWHILE @@FETCH_STATUS=0BEGINSELECT @Datass=Datass FROM Table_1 WHERE Material=@Material AND Projects=@ProjectsSET @Formula=REPLACE(@Formula,@Projects,@Datass) --replace替换公式FETCH NEXT FROM my_cur2 INTO @ProjectsENDPRINT @Material PRINT @Formula SET @Sql='select '+@FormulaEXEC (@Sql)PRINT @DatassCLOSE my_cur2DEALLOCATE my_cur2FETCH NEXT FROM my_cur1 INTO @MaterialENDCLOSE my_cur1DEALLOCATE my_cur1
并把他的结果添加到临时表 让所有的字段现实出来

查看全部
qq_37889561
som@''
2017/08/25 05:50
  • orcale
  • sql
  • 点赞
  • 收藏
  • 回答
    私信
满意答案
查看全部

3个回复