Issue with PL-SQL: ORA-06550

萝らか妹 提交于 2019-12-26 05:40:58

问题


I'm trying to learn a bit of PL-SQL using a tutorial by examples book, but one of the suggested codes return the following error when run:

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

Could you please help me understand what I'm doing wrong?

Many thanks in advance! Simone.

SQL Fiddle

Oracle 11g R2 Schema Setup:

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'));

Query 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:


回答1:


you are trying to insert 5 values from your select into four variables.




回答2:


This is correct:

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


来源:https://stackoverflow.com/questions/29306209/issue-with-pl-sql-ora-06550

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!