DB2版本的Query

时间:2014-02-11 05:32:58

标签: oracle db2

我是DB2的新手,并且很想知道如何在DB2中编写以下查询。这是我所知道的一个相当基本的问题,我只想对两者进行比较。

DECLARE
CURSOR CURRSOR IS 
 SELECT * FROM EMPLOYEES WHERE EMPNO=100;
BEGIN
   FOR i IN CURRSOR 
       LOOP
           DBMS_OUTPUT.PUT_LINE('THE NAME OF THE EMPLOYEE IS'|| i.ename);
       END LOOP;
EXCEPTION 
        WHEN NO_DATA_FOUND THEN 
           RAISE_APPLICATION_ERROR(-20001,'THERE IS NO EMPLOYEE WITH EMPLOYEE NUMBER 100');
END;

1 个答案:

答案 0 :(得分:0)

    BEGIN
    FOR each_record AS
    c1 CURSOR FOR
        SELECT * from EMPLOYEES 
    DO 
        DBMS_OUTPUT.PUT('THE NAME OF THE EMPLOYEE IS'|| ENAME);
    END FOR; 
    EXCEPTION
       WHEN NO_DATA_FOUND THEN
          RAISE_APPLICATION_ERROR(-20001, 'THERE IS NO EMPLOYEE WITH EMPLOYEE NUMBER 100');
    END;