PL-SQL 问题:ORA-06550

Issue with PL-SQL: ORA-06550

我正在尝试使用示例书的教程学习一些 PL-SQL,但是建议的代码之一 return 在 运行 时出现以下错误:

ORA-06550: line 10, column 48: PL/SQL: ORA-00947: not enough values ORA-06550: line 9, column 1: PL/SQL: SQL Statement ignored

你能帮我理解我做错了什么吗?

非常感谢! 西蒙.

SQL Fiddle

Oracle 11g R2 模式设置:

create table product (code integer primary key, name varchar2 (20), type varchar2(8),price number(4,2),update_dt date);
insert into product values(1,'Mela','Frutta',1,to_date('1-MAY-2015','DD-MON-YYYY'));
insert into product values(2,'Pera','Frutta',2,to_date('2-MAY-2015','DD-MON-YYYY'));
insert into product values(3,'Carota','Ortaggio',3,to_date('3-MAY-2015','DD-MON-YYYY'));
insert into product values(4,'Zucchina','Ortaggio',4,to_date('4-MAY-2015','DD-MON-YYYY'));
insert into product values(5,'Arancia','Frutta',5,to_date('5-MAY-2015','DD-MON-YYYY'));

查询 1:

declare 
code_var integer;
type_var varchar2(8);
name_var varchar2(20);
price_var number(4,2);
update_dt_var date;
price_too_high exception;
begin
select code, type,name, price, update_dt
into code_var,type_var,price_var,update_dt_var
from product
where name='Arancia';
if price_var > 4.5 then
raise price_too_high;
end if;
exception
when price_too_high then
dbms_output.put_line('price is too damn high!');
end;

Results:

您正在尝试将 select 中的 5 个值插入到四个变量中。

这是正确的:

select code,     type,     name,     price,     update_dt
into   code_var, type_var, name_var, price_var, update_dt_var
from   product
where  name='Arancia';