SQL Server 将Oracle过程转换为MSSQL

zazmityj  于 2023-01-25  发布在  Oracle
关注(0)|答案(1)|浏览(84)

我试图将此过程从Oracle转换为Microsoft SQL。我使用SQLINE没有成功。代码应该插入到行到表中。它在Oracle中运行良好,只是想在MSSQL中做一些类似的事情。
这是过程

```create or replace procedure insert_emp as 
    begin
for p in 0..1000 loop
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||1,'Bob',30000,'02-FEB-2004','SALES','EMP');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||2,'Raj',80000,'02-MAR-2018','MRKTNG','EMP');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||3,'Kevin',90000,'05-APR-2010','ADMIN','EMP');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||4,'Laila',30000,'12-FEB-2004','PURCHASE','EMP');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||5,'Steve',100000,'15-JAN-2008','SALES','MGR');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||6,'Lucy',80000,'10-FEB-2014','MRKTNG','MGR');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||7,'Nathan',120000,'17-JUN-2012','ADMIN','MGR');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||8,'Jose',60000,'16-JUL-2015','DESIGN','EMP');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||9,'Andrew',80000,'18-AUG-2005','SALES','EMP');
insert into emp (empno, empname, salary, hiredate, dept, title) values(p||10,'Lata',90000,'02-FEB-1998','SALES','EMP');
end loop;
commit;
end ;```

这是在SQLINE中转换的proc,但它不能在MSSQL中运行。

```begin
declare p cursor for 0..1000 open p;
 fetch p into;
 while @@fetch_status=0
 begin   
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+1,'bob',30000,'02-feb-2004','sales','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+2,'raj',80000,'02-mar-2018','mrktng','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+3,'kevin',90000,'05-apr-2010','admin','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+4,'laila',30000,'12-feb-2004','purchase','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+5,'steve',100000,'15-jan-2008','sales','mgr');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+6,'lucy',80000,'10-feb-2014','mrktng','mgr');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+7,'nathan',120000,'17-jun-2012','admin','mgr');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+8,'jose',60000,'16-jul-2015','design','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+9,'andrew',80000,'18-aug-2005','sales','emp');
if p<>0 begin  
insert into emp (empno, empname, salary, hiredate, dept, title) values(isnull(p, '')+0,'lata',90000,'02-feb-1998','sales','emp');
end 
fetch p into;
end;
close p;
deallocate p;
commit;
end;```

谢谢!

nlejzf6q

nlejzf6q1#

DECLARE @P INT = 0;
WHILE @P < 100
begin   
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+1,'bob',30000,'02-feb-2004','sales','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+2,'raj',80000,'02-mar-2018','mrktng','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+3,'kevin',90000,'05-apr-2010','admin','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+4,'laila',30000,'12-feb-2004','purchase','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+5,'steve',100000,'15-jan-2008','sales','mgr');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+6,'lucy',80000,'10-feb-2014','mrktng','mgr');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+7,'nathan',120000,'17-jun-2012','admin','mgr');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+8,'jose',60000,'16-jul-2015','design','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+9,'andrew',80000,'18-aug-2005','sales','emp');
insert into emp (empno, empname, salary, hiredate, dept, title) values(@P+0,'lata',90000,'02-feb-1998','sales','emp');
SET @P+=1;
end ;

相关问题