如何从用户获取deptno号并打印所有员工,属于Oracle 11g中的deptno 10

时间:2016-05-22 09:14:32

标签: oracle

如何从用户获取deptno号并打印所有员工,属于Oracle 11g中的deptno 10

**Answer is
    declare
        cursor a(T number) is
        Select *from EMp where Deptno = T;
        Em a%rowtype;
    begin
        open a(&b);
            loop
            Fetch a into Em;
            exit when a%notfound;
            dbms_output.put_line(Em.EName);
            end loop;
    END;
    /**

2 个答案:

答案 0 :(得分:1)

declare

    cursor a(T number) is
    Select *from EMp where Deptno = T;
    Em a%rowtype;
begin
    open a(&b);
        loop
        Fetch a into Em;
        exit when a%notfound;
        dbms_output.put_line(Em.EName);
        end loop;
END;
/

答案 1 :(得分:0)

您可以使用隐式游标来简化代码(当然,T必须提供给下面的代码块):

BEGIN
    FOR i IN (
        SELECT *
          FROM emp
         WHERE deptno = T
    ) LOOP
        dbms_output.put_line(i.EName);
    END LOOP;
END;