我目前陷入这个pl / sql问题,我正在尝试将某个位置(3个不同的表)申请的申请人的所有信息收集到存储过程中。
不幸的是,我对oracle和pl / sql还是很陌生,所以我认为我的联接可能很草率,而且我的主要问题dbms_output.put_line没有打印出我需要的数据。我认为这可能是在代码块中的错误位置,或者是我的join语句中一直存在一个问题。
enter code here
SET ECHO ON
SET FEEDBACK ON
SET LINESIZE 100
SET PAGESIZE 100
SET SERVEROUTPUT ON
CREATE OR REPLACE PROCEDURE APPLICANTS IS
first_name APPLICANT.FNAME%TYPE;
last_name APPLICANT.LNAME%TYPE;
position_number APPLIES.PNUMBER%TYPE;
position_title POSITION.TITLE%TYPE;
str VARCHAR(300);
CURSOR fnameCursor IS
SELECT FNAME
FROM APPLICANT;
BEGIN
FOR fnameCursor IN (SELECT APPLICANT.LNAME, APPLIES.PNUMBER,
POSITION.TITLE INTO last_name, position_number, position_title
FROM APPLICANT JOIN APPLIES ON APPLICANT.ANUMBER =
APPLIES.ANUMBER
JOIN POSITION ON POSITION.PNUMBER = APPLIES.PNUMBER
WHERE FNAME = first_name
ORDER BY LNAME DESC)
LOOP
str := position_number || '' || first_name || '' || last_name || ': ' ||
position_title;
dbms_output.put_line(str);
--EXIT WHEN fnameCursor%NOTFOUND;
END LOOP;
END APPLICANTS;
/
EXECUTE APPLICANTS;
答案 0 :(得分:2)
令人惊讶的是,该过程正在编译。您正在隐式游标查询中使用INTO
子句。另外,我相信first_name
应该作为您过程的一个论据,但您没有提到它。
更重要的是,应该使用游标的记录变量fnamecursor
CREATE OR REPLACE PROCEDURE APPLICANTS(first_name APPLICANT.FNAME%TYPE)
IS
str VARCHAR(300);
BEGIN
FOR fnamecursor IN (
SELECT applicant.lname as last_name,
applies.pnumber as position_number,
position.title as position_title
FROM applicant
JOIN applies ON applicant.anumber = applies.anumber
JOIN position ON position.pnumber = applies.pnumber
WHERE fname = first_name
ORDER BY lname DESC
) LOOP
str := fnamecursor.position_number || ' ' || first_name || ' ' ||
fnamecursor.last_name || ': ' || fnamecursor.position_title;
dbms_output.put_line(str);
END LOOP;
END applicants;
/