PL-SQL问题:ORA-06550

时间:2015-03-27 17:03:44

标签: sql plsql oracle11g ora-06550

我尝试使用示例书中的教程来学习一些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;

Results

2 个答案:

答案 0 :(得分:2)

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

答案 1 :(得分:0)

这是正确的:

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