CREATE OR REPLACE procedure verify_employee IS
Emp_name trkemployee.name#%TYPE,
Emp_ID trkemployee.E#%TYPE,
CURSOR c1;
IS
select e.e#, e.name from trkemployee e where e# IN (select e# from trkdriver intersect select e# from trkmechanic);
IN
(select e# from trkdriver intersect select e# from trkmechanic);
BEGIN
OPEN c1();
LOOP
END LOOP;
close c1;
END;
/
以上是我的 PL/SQL 代码。我想要实现的是列出所有同时担任司机和机械师的员工。
我在终端单独执行sql语句,输出如下..
SQL> select e.e#, e.name from trkemployee e where e# IN (select e# from trkdriver intersect select e# from trkmechanic);
E# NAME
---------- --------------------------------------------------
14 Andrew R. Smith
但我想在 PL/SQL 中执行并执行 DMBS_OUTPUT.PUT(result);
我知道要检查多条记录,我需要使用游标。假设将来会有超过 1 行返回,我应该如何更改我的 pl/sql 以及当我加载程序时,终端说编译错误。
下面是我的3张桌子..
SQL> desc trkdriver;
Name Null? Type
----------------------------------------- -------- ----------------------------
E# NOT NULL NUMBER(12)
L# NOT NULL NUMBER(8)
STATUS NOT NULL VARCHAR2(10)
SQL> desc trkmechanic;
Name Null? Type
----------------------------------------- -------- ----------------------------
E# NOT NULL NUMBER(12)
L# NOT NULL NUMBER(8)
STATUS NOT NULL VARCHAR2(10)
EXPERIENCE NOT NULL VARCHAR2(10)
SQL> desc trkemployee;
Name Null? Type
----------------------------------------- -------- ----------------------------
E# NOT NULL NUMBER(12)
NAME NOT NULL VARCHAR2(50)
DOB DATE
ADDRESS NOT NULL VARCHAR2(300)
HIREDATE NOT NULL DATE