程序错误 - PLS-00103 遇到符号“>”
Procedure error - PLS-00103 Encountered the symbol ">"
我正在尝试学习 PLSQL,但在创建过程时遇到问题。
我要解决的任务是:创建一个程序来检查佣金。高于 0.35 的佣金只能输入工作经验超过 15 年的员工。如果佣金较高或实践较低,则会打印错误。利用异常(Exception and Raise)来定义错误信息。
我写了这个,但是有错误:
PLS-00103 Encountered the symbol ">" when expecting one of following::= . ( @ % ;
create or replace PROCEDURE PROVIZIA(num in number) IS
employee_id number;
com_pct employees.commission_pct%type;
begin
select commission_pct into com_pct from employees where employee_id = num;
if PRAX(employee_id) > 15 then
com_pct > 0.35;
else PRAX(employee_id) < 15 then
com_pct < 0.35;
end if;
exception when com_pct > 0.35 and PRAX(employee_id) < 15 then
dbms_output.put_line('error');
raise;
end PROVIZIA;
你能告诉我哪里出错了吗?
谢谢。
假设这是一个测试用例(table 和 prax
函数,其中 returns 一些数字;我不知道是哪个以及为什么,所以我做了它 [= =25=] 员工 1
的“无效”值:
SQL> create table employees as
2 select 1 employee_id, 0.5 commission_pct from dual union all
3 select 2, 0.2 from dual;
Table created.
SQL> create or replace function prax(par_empid in number) return number is
2 begin
3 return case when par_empid = 1 then 10
4 else 50
5 end;
6 end prax;
7 /
Function created.
SQL> select employee_id, commission_pct, prax(employee_id) prax_result
2 from employees;
EMPLOYEE_ID COMMISSION_PCT PRAX_RESULT
----------- -------------- -----------
1 ,5 10 --> this combination is invalid
2 ,2 50 --> this is OK
SQL>
如果值“错误”则引发错误的过程;不做任何其他事情(因为你没有说在那种情况下该怎么做):
SQL> create or replace procedure provizia(num in number) is
2 com_pct employees.commission_pct%type;
3 l_err exception;
4 begin
5 select commission_pct
6 into com_pct
7 from employees
8 where employee_id = num;
9
10 if com_pct > 0.35 and prax(num) < 15 then
11 raise l_err;
12 end if;
13
14 exception
15 when l_err then
16 raise_application_error(-20000, 'Error');
17 end provizia;
18 /
Procedure created.
SQL>
我们来测试一下:
SQL> exec provizia(num => 1);
BEGIN provizia(num => 1); END;
*
ERROR at line 1:
ORA-20000: Error
ORA-06512: at "SYS.PROVIZIA", line 16
ORA-06512: at line 1
SQL> exec provizia(num => 2);
PL/SQL procedure successfully completed.
SQL>
现在您有了一个工作示例,请随时改进它。
com_ptc > 0.35
不能这样写。
就return你是真是假。
查看给定的像素。
如果您使用 TOAD.exe 那么您将通知运行时错误。
查看标记区域。
我们试试这个
CREATE OR REPLACE PROCEDURE PROVIZIA (num IN NUMBER)
IS
employee_id NUMBER;
com_pct employees.commission_pct%TYPE;
BEGIN
SELECT commission_pct
INTO com_pct
FROM employees
WHERE employee_id = num;
IF com_pct > 0.35 AND PRAX (employee_id) < 15
THEN
DBMS_OUTPUT.put_line ('error');
ELSE
DBMS_OUTPUT.put_line ('OK');
END IF;
END PROVIZIA;
我正在尝试学习 PLSQL,但在创建过程时遇到问题。
我要解决的任务是:创建一个程序来检查佣金。高于 0.35 的佣金只能输入工作经验超过 15 年的员工。如果佣金较高或实践较低,则会打印错误。利用异常(Exception and Raise)来定义错误信息。
我写了这个,但是有错误:
PLS-00103 Encountered the symbol ">" when expecting one of following::= . ( @ % ;
create or replace PROCEDURE PROVIZIA(num in number) IS
employee_id number;
com_pct employees.commission_pct%type;
begin
select commission_pct into com_pct from employees where employee_id = num;
if PRAX(employee_id) > 15 then
com_pct > 0.35;
else PRAX(employee_id) < 15 then
com_pct < 0.35;
end if;
exception when com_pct > 0.35 and PRAX(employee_id) < 15 then
dbms_output.put_line('error');
raise;
end PROVIZIA;
你能告诉我哪里出错了吗?
谢谢。
假设这是一个测试用例(table 和 prax
函数,其中 returns 一些数字;我不知道是哪个以及为什么,所以我做了它 [= =25=] 员工 1
的“无效”值:
SQL> create table employees as
2 select 1 employee_id, 0.5 commission_pct from dual union all
3 select 2, 0.2 from dual;
Table created.
SQL> create or replace function prax(par_empid in number) return number is
2 begin
3 return case when par_empid = 1 then 10
4 else 50
5 end;
6 end prax;
7 /
Function created.
SQL> select employee_id, commission_pct, prax(employee_id) prax_result
2 from employees;
EMPLOYEE_ID COMMISSION_PCT PRAX_RESULT
----------- -------------- -----------
1 ,5 10 --> this combination is invalid
2 ,2 50 --> this is OK
SQL>
如果值“错误”则引发错误的过程;不做任何其他事情(因为你没有说在那种情况下该怎么做):
SQL> create or replace procedure provizia(num in number) is
2 com_pct employees.commission_pct%type;
3 l_err exception;
4 begin
5 select commission_pct
6 into com_pct
7 from employees
8 where employee_id = num;
9
10 if com_pct > 0.35 and prax(num) < 15 then
11 raise l_err;
12 end if;
13
14 exception
15 when l_err then
16 raise_application_error(-20000, 'Error');
17 end provizia;
18 /
Procedure created.
SQL>
我们来测试一下:
SQL> exec provizia(num => 1);
BEGIN provizia(num => 1); END;
*
ERROR at line 1:
ORA-20000: Error
ORA-06512: at "SYS.PROVIZIA", line 16
ORA-06512: at line 1
SQL> exec provizia(num => 2);
PL/SQL procedure successfully completed.
SQL>
现在您有了一个工作示例,请随时改进它。
com_ptc > 0.35
不能这样写。
就return你是真是假。
查看给定的像素。
如果您使用 TOAD.exe 那么您将通知运行时错误。
查看标记区域。
我们试试这个
CREATE OR REPLACE PROCEDURE PROVIZIA (num IN NUMBER)
IS
employee_id NUMBER;
com_pct employees.commission_pct%TYPE;
BEGIN
SELECT commission_pct
INTO com_pct
FROM employees
WHERE employee_id = num;
IF com_pct > 0.35 AND PRAX (employee_id) < 15
THEN
DBMS_OUTPUT.put_line ('error');
ELSE
DBMS_OUTPUT.put_line ('OK');
END IF;
END PROVIZIA;