DB2和Oracle常用语法的区别

1、变量赋值
   oracle: i := 1;
   db2: set i = 1;
2、For循环
   1)案例1:
   oracle:
   FOR I IN SQL LOOP
      .....
   END LOOP;
   db2:
   FOR I AS SQL DO
      .....
   END FOR;
   2)案例2:
   oracle:
   FOR I IN 1..3 LOOP
      .....
   END LOOP;
   db2:
   SET I = 1;
   WHILE I <= 3 DO
      .....
      SET I = I + 1;
   END WHILE;
3、IF语句
   oracle: IF .. THEN .. ELSIF .. THEN .. ELSE .. END IF;
   db2:    IF .. THEN .. ELSEIF .. THEN .. ELSE .. END IF;
4、动态执行SQL语句
   1)案例1:
   oracle: EXECUTE IMMEDIATE mySQL INTO v_num;
   db2:    VALUES mySQL INTO v_num;
   2)案例2:
   oracle: EXECUTE IMMEDIATE mySQL
   db2:    PREPARE S1 FROM mySQL;
           EXECUTE S1;
5、虚拟表
   oracle:DUAL
   db2:   SYSIBM.SYSDUMMY1或SYSIBM.DUAL或VALUES
           例如:SELECT '12345' FROM SYSIBM.DUAL
                 VALUES '12345'
6、oracle、db2都存在TO_CHAR、TO_DATE、SYSDATE
7、查询数据库中存储过程:SELECT * FROM SYSCAT.PROCEDURES 

你可能感兴趣的:(oracle,db2)