【发布时间】:2020-11-08 03:42:36
【问题描述】:
目前正在开发oracle PLSQL函数,用于列出项目编号、职位和从事每个项目的员工姓名。
对于这个函数,我需要得到这样的输出: 【片段示例】
1001 Computation: Alvin, Peter
1002 Study methods: Bob, Robert
1003 Racing car: Robert
这是我目前的输出。 SQL> 执行项目组;
1001 Computation: Alvin
1001 Computation: Ami
1001 Computation: Michael
1001 Computation: Peter
1001 Computation: Wendy
1002 Study methods: Bob
1002 Study methods: Robert
1003 Racing car: Bob
1003 Racing car: Robert
1004 Football: Douglass
1004 Football: Eadger
1005 Swimming: Douglass
1005 Swimming: Eadger
1006 Training: Aban
1006 Training: Carl
[当前代码]
SQL> set echo on
SQL> set feedback on
SQL> set linesize 100
SQL> set pagesize 200
SQL> set serveroutput on
SQL> --
SQL> -- Task 01
SQL> --
SQL> CREATE OR REPLACE PROCEDURE PROJECTGROUPS
2 IS
3 Previous_pnum PROJECT.P#%type := -1;
4 --
5 begin
6 for currentRow IN(select p.P#, p.PTITLE, e.NAME
7 from PROJECT p LEFT OUTER JOIN EMPLOYEE e
8 on p.d# = e.d#
9 WHERE p.P# IN(1001,1002,1003,1004,1005,1006)
10 ORDER BY p.P#, p.PTITLE, e.NAME)
11 --
12 --
13 loop
14 if currentRow.P# is not null then
15 dbms_output.put_line(currentRow.P# || ' ' || currentRow.PTITLE || ': ' || currentRow.NAME);
16 end if;
17 Previous_pnum := currentRow.P#;
18 end loop;
19 dbms_output.put_line(NULL);
20 END;
21 /
Procedure created.
【问题讨论】:
-
您使用哪个 Oracle 数据库版本?
标签: oracle plsql stored-functions