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
并把他的结果添加到临时表 让所有的字段现实出来

3个回答

需要把他的结果添加到 临时表让他 把所有列都显示出来,求大神帮忙

 CREATE TABLE [dbo].[Table_1](
    [ID] [nvarchar](50) NULL,
    [Material] [nvarchar](50) NULL,
    [Projects] [nvarchar](50) NULL,
    [Calculate] [nvarchar](50) NULL,
    [Datass] [nvarchar](50) NULL,
    [Formula] [nvarchar](50) NULL,
    [Tolerance] [nvarchar](50) NULL,
    [Standard] [nvarchar](50) NULL
) ON [PRIMARY]

GO
INSERT 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_cur1

FETCH NEXT FROM my_cur1 INTO @Material
WHILE @@FETCH_STATUS=0
BEGIN
SELECT @Formula = Formula FROM Table_1 WHERE Material=@Material

DECLARE my_cur2 CURSOR FOR --读取Project
SELECT Projects FROM Table_1 WHERE Material=@Material AND Calculate<>'是'
OPEN my_cur2
FETCH NEXT FROM my_cur2 INTO @Projects
WHILE @@FETCH_STATUS=0
BEGIN
SELECT @Datass=Datass FROM Table_1 WHERE Material=@Material AND Projects=@Projects
SET @Formula=REPLACE(@Formula,@Projects,@Datass) --replace替换公式
FETCH NEXT FROM my_cur2 INTO @Projects
END
PRINT @Material 
PRINT @Formula 

SET @Sql='select '+@Formula
EXEC (@Sql)
PRINT @Datass

CLOSE my_cur2
DEALLOCATE my_cur2

FETCH NEXT FROM my_cur1 INTO @Material
END
CLOSE my_cur1
DEALLOCATE my_cur1


你好,你的意思是sql语句转换成orcale,在显示在ORACLE中吗?

qq_37889561
som@'' 回复XianRenShan: 没用过Orcale,,,所以才需要帮助啊
大约 2 年之前 回复
XianRenShan
XianRenShan 我觉得你可以直接用ORACLE语句写
大约 2 年之前 回复
qq_37889561
som@'' 是的 而且 需要 把结果显示成 所有项都显示
大约 2 年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!