将oracle脚本转换为mysql脚本

时间:2015-08-21 12:40:45

标签: mysql sql oracle syntax sql-insert

需要帮助我将数据库从oracle迁移到mysql。我在oracle运行以下查询它工作正常,但在mysql获取

INSERT INTO xyz(rid, pid)
SELECT rid, pid
  FROM ((SELECT distinct rd, 
              (SELECT p.pid FROM abc p WHERE p.permission='jury') AS pid
          FROM xyz
         WHERE pid IN (SELECT p.pid
                         FROM abc p
                        WHERE p.permission in ('jury'))
       ));

获得以下错误

Every derived table must have its own alias [SQL State=42000, DB Errorcode=1248]

1 个答案:

答案 0 :(得分:1)

我不是MySQL用户,但谷歌搜索错误表明它希望内联视图有一个别名:

insert into xyz (rid, pid)
  select rid, pid
  from   ( (select distinct rd,
                            (select p.pid
                             from   abc p
                             where  p.permission = 'jury')
                              as pid
            from   xyz
            where  pid in (select p.pid
                           from   abc p
                           where  p.permission in ('jury')))) res;

然而,这并不是一种非常非常复杂的做法:

insert into xyz (rid, pid)                         
select distinct xyz.rd,
                abc.pid
from   xyz
       inner join abc on (xyz.pid = abc.pid and abc.permission = 'jury');