将视图从oracle转换为mysql

时间:2016-12-01 11:51:51

标签: mysql oracle view

以下是oracle查询,

    CREATE OR REPLACE VIEW view1 AS
 SELECT t1.col1,t1.col2
       FROM (select * FROM table1 asap, table2 pids where asap.parentid= pids.parentid) t1,
            (select * from table1 r_asap,table3 ids where r_asap.id=ids.id) t2
        WHERE
             t1.col2=t2.col2 and
             (t2.col3 <>t1.col3 OR
              t2.col4<>t1.col4 OR
       t2.col5 <>t1.col5 )
       order by t1.col1

我需要将其转换为MYSQL视图..任何人都可以帮助我

1 个答案:

答案 0 :(得分:0)

这应该是mysql兼容的,但总体上使用显式连接(对我来说更具可读性)

并且由于mysql不允许在视图中使用子查询,您必须首先为子选择创建一个视图,并在此构建最终视图

    CREATE OR REPLACE VIEW view_sub1 AS
    SELECT col1, col2 
    FROM table1 asap 
    INNER JOIN  table2 pids on asap.parentid= pids.parentid;

    CREATE OR REPLACE VIEW view_sub2 AS
    SELECT c2l2
    FROM table1 r_asap
    INNER JOIN table3 ids on  r_asap.id=ids.id ;

    CREATE OR REPLACE VIEW view1 AS
    SELECT view_sub1.col1,view_sub1.col2
    FROM view_sub1
    INNER JOIN view_sub2 on view_sub1.col2=view_sub2.col2  
    WHERE view_sub2.col3 <>view_sub1.col3 
    OR    view_sub2.col4<>view_sub1.col4
    OR    view_sub2.col5 <>view_sub1.col5;