我正试图使用示例教程来学习一些PL-SQL,但其中一个建议的代码在运行时返回以下错误:
ORA-06550:第10行,第48列:PL/SQL:ORA-00947:值不足ORA-06550:第9行第1列:PL/SQL:SQL语句已忽略
你能帮我理解我做错了什么吗?
非常感谢!西蒙。
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;
结果:
您正试图将选择中的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';