我得到的Oracle错误ORA-00972标识符太长了。这可能是由于这一行
WHERE EMPLOYEE_ID =& e;
但我无法理解。
为了测试这一点,我删除了所有CASE语句和serverout语句,但在运行时输入员工ID后仍然出现错误。
运行时附加了错误的图像。 Error
set echo on
spool c:\cs422a\wa4spool.txt
SET SERVEROUT ON
DECLARE Emp_rec HR.EMPLOYEES%ROWTYPE;
BEGIN
SELECT *
INTO Emp_rec
FROM HR.EMPLOYEES
WHERE EMPLOYEE_ID = &e;
DBMS_OUTPUT.PUT_LINE("---------------------------------------');
CASE Emp_rec.Department_ID
WHEN 10 THEN DBMS_OUTPUT.PUT_LINE('Department: Administration');
WHEN 20 THEN DBMS_OUTPUT.PUT_LINE('Department: Marketing');
WHEN 30 THEN DBMS_OUTPUT.PUT_LINE('Department: Purchasing');
WHEN 40 THEN DBMS_OUTPUT.PUT_LINE('Department: Human Resources');
WHEN 50 THEN DBMS_OUTPUT.PUT_LINE('Department: Shipping');
WHEN 60 THEN DBMS_OUTPUT.PUT_LINE('Department: IT');
WHEN 70 THEN DBMS_OUTPUT.PUT_LINE('Department: Public Relations');
WHEN 80 THEN DBMS_OUTPUT.PUT_LINE('Department: Sales');
WHEN 90 THEN DBMS_OUTPUT.PUT_LINE('Department: Executive');
WHEN 100 THEN DBMS_OUTPUT.PUT_LINE('Department: Finance');
WHEN 110 THEN DBMS_OUTPUT.PUT_LINE('Department: Accounting');
WHEN 120 THEN DBMS_OUTPUT.PUT_LINE('Department: Treasury');
WHEN 130 THEN DBMS_OUTPUT.PUT_LINE('Department: Corporate Tax');
WHEN 140 THEN DBMS_OUTPUT.PUT_LINE('Department: Control and Credit');
WHEN 150 THEN DBMS_OUTPUT.PUT_LINE('Department: Shareholder Services');
WHEN 160 THEN DBMS_OUTPUT.PUT_LINE('Department: Benefits');
WHEN 170 THEN DBMS_OUTPUT.PUT_LINE('Department: Manufacturing');
WHEN 180 THEN DBMS_OUTPUT.PUT_LINE('Department: Construction');
WHEN 190 THEN DBMS_OUTPUT.PUT_LINE('Department: Contracting');
WHEN 200 THEN DBMS_OUTPUT.PUT_LINE('Department: Operations');
WHEN 210 THEN DBMS_OUTPUT.PUT_LINE('Department: IT Support');
WHEN 220 THEN DBMS_OUTPUT.PUT_LINE('Department: NOC');
WHEN 230 THEN DBMS_OUTPUT.PUT_LINE('Department: IT Helpdesk');
WHEN 240 THEN DBMS_OUTPUT.PUT_LINE('Department: Government Sales');
WHEN 250 THEN DBMS_OUTPUT.PUT_LINE('Department: Retail Sales');
WHEN 260 THEN DBMS_OUTPUT.PUT_LINE('Department: Recruiting');
WHEN 270 THEN DBMS_OUTPUT.PUT_LINE('Department: Payroll');
END CASE;
DBMS_OUTPUT.PUT_LINE('Department: ' || Emp_rec.DEPARTMENT_ID);
DBMS_OUTPUT.PUT_LINE('Employee ID: ' || Emp_rec.EMPLOYEE_ID);
DBMS_OUTPUT.PUT_LINE('Employee First Name: ' || Emp_rec.FIRST_NAME);
DBMS_OUTPUT.PUT_LINE('Employee Last Name: ' || Emp_rec.LAST_NAME);
DBMS_OUTPUT.PUT_LINE('Salary: ' || Emp_rec.SALARY);
DBMS_OUTPUT.PUT_LINE('---------------------------------------');
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('No data found.');
END;
/
答案 0 :(得分:2)
第9行有一个拼写错误:
DBMS_OUTPUT.PUT_LINE("---------------------------------------');
有双引号,应该是单引号。
在标识符中使用双引号来强制区分大小写(有关详细信息,请参阅this question)。
在您的示例中,PL / SQL解析器认为您正在尝试使用名为-----------------------------的变量----------(...)这会导致ORA-00972。