我正在尝试执行if语句来确定employee_id,但是每次运行该程序时,都会不断出错。这是我与数据库交互的记录:
`enter code here`SQL> SET SERVEROUT ON FORMAT TRUNCATED
`enter code here`SQL> DECLARE
`enter code here` 2
`enter code here`3 EMP_REC HR.EMPLOYEES%ROWTYPE;
`enter code here`4 BEGIN
`enter code here`5 DBMS_OUTPUT.PUT_LINE ('---------------------------------------');
`enter code here`6 FOR EMP_REC
`enter code here`7 (SELECT *
`enter code here`8 FROM HR.EMPLOYEES
`enter code here`9 WHERE EMPLOYEE_ID = 5)
`enter code here`10 LOOP
`enter code here`11 IF
`enter code here`12 IF (EMP_REC.EMPLOYEE_ID = 5) THEN
`enter code here`13 DBMS_OUTPUT.PUT_LINE ('EMPLOYEE_ID: ' || EMP_REC.EMPLOYEE_ID) ;
`enter code here` 14 DBMS_OUTPUT.PUT_LINE ('FIRST_NAME: ' || EMP_REC.FIRST_NAME) ;
`enter code here` 15 DBMS_OUTPUT.PUT_LINE ('LAST_NAME: ' || EMP_REC.LAST_NAME) ;
`enter code here` 16 DBMS_OUTPUT.PUT_LINE ('SALARY: ' || TO_CHAR (EMP_REC.SALARY, '$999,999'));
`enter code here` 17 DBMS_OUTPUT.PUT_LINE ('---------------------------------------');
`enter code here` 18 END LOOP;
`enter code here`19 END IF;
`enter code here`20 EXCEPTION
`enter code here`21 WHEN NO_DATA_FOUND THEN
`enter code here`22 DBMS_OUTPUT.PUT_LINE ('NO DATA FOUND.');
`enter code here`23
`enter code here`24 END;
`enter code here`25 /
这是正在报告的错误:
(SELECT *
*
ERROR at line 7:
ORA-06550: line 7, column 1:
PLS-00103: Encountered the symbol "(" when expecting one of the following:
in
The symbol "in" was substituted for "(" to continue.
ORA-06550: line 12, column 1:
PLS-00103: Encountered the symbol "IF" when expecting one of the following:
( - + case mod new not null <an identifier>
<a double-quoted delimited-identifier> <a bind variable>
continue avg count current exists max min prior sql
ORA-06550: line 18, column 5:
PLS-00103: Encountered the symbol "LOOP" when expecting one of the following:
if
您可以使用它来确定他们工作的部门,就像我们过去使用CASE所做的那样。 如果他们赚了一定的钱,您可以用它来打印一条消息。 如果在某个日期之前被雇用,也许他们应该加薪。