MS SQL Server到Oracle脚本转换

时间:2017-12-19 15:50:57

标签: sql-server oracle plsql database-migration

我在SQL Server中编写了一个脚本,现在看起来我需要在Oracle中使用它。我现在尝试了一段时间,除了不断收到一些错误之外,我无法通过我的尝试实现任何目标。 有人可以告诉我如何修改以下脚本,以便它可以在Oracle中工作吗?

DECLARE @oid VARCHAR(50);
DECLARE @toids TABLE (oid VARCHAR(50))
INSERT INTO @toids (oid) SELECT oid FROM awftask WHERE oid in (SELECT oid 
FROM agltransactmap)



WHILE (SELECT COUNT(*) FROM @toids WHERE oid IS NOT NULL) > 0
BEGIN
SET @oid = (SELECT TOP 1 oid FROM @toids); 

INSERT INTO awftaskfin (some staff) FROM awftask
WHERE oid in (@oid);

这里有一些其他的插入和删除,然后脚本结束:

END

我真的很感激任何帮助。

1 个答案:

答案 0 :(得分:0)

CREATE TYPE StringList IS TABLE OF VARCHAR2(50);
/

DECLARE
  toid StringList;
BEGIN
  SELECT oid
  BULK COLLECT INTO toid
  FROM   awftask
  WHERE  oid IN ( SELECT oid FROM agltransactmap );

  FOR i IN 1 .. toid.COUNT LOOP
    INSERT INTO awftaskfin (some staff) VALUES ( toid(i) );
    -- here are some other inserts and deletes
  END LOOP;
END;
/