(第一次发布)并使用Brewbean数据库在Oracle 10g中使用简单循环语句时出现问题。我不知道我做错了什么,我已多次尝试将select语句更改为第二个表(bb_shopper)的主键,oracle仍然返回相同的错误。我不明白这一点。
问题来自:创建一个循环,根据项目的价格和可用的总可用金额确定可购买的商品数量,使用一个初始化变量来表示价格金额,另一个变为代表可用的总额。
我的回答:
SQL> /* 2-6 Loop */
SQL>
SQL> declare
2 v_idshopper bb_basket.idshopper%type;
3 v_price bb_product.price%type;
4 v_stock bb_product.stock%type;
5 v_firstname bb_shopper.firstname%type;
6 v_lastname bb_shopper.lastname%type;
7 v_idproduct bb_product.idproduct%type;
8 begin
9 select price, stock, firstname, lastname
10 into v_price, v_stock, v_firstname, v_lastname
11 from bb_product join bb_shopper using (idproduct)
12 where v_idproduct like idproduct
13 group by firstname, lastname;
14
15 for i in 21..27 LOOP
16 dbms_output.put_line('Customer is ' ||v_idshopper ||' ' ||v_firstname ||' ' ||v_lastname);
17 dbms_output.put_line('The total number of items that can be purchased is '||v_stock);
18 dbms_output.put_line('The total amount that would be spend is '||v_price);
19 end loop;
20 end;
21 /
from bb_product join bb_shopper using (idproduct)
*
ERROR at line 11:
ORA-06550: line 11, column 41:
PLS-00302: component 'IDPRODUCT' must be declared
ORA-06550: line 11, column 41:
PL/SQL: ORA-00904: "BB_SHOPPER"."IDPRODUCT": invalid identifier
ORA-06550: line 9, column 2:
PL/SQL: SQL Statement ignored
不太确定我是否应该发布我从中提取此数据的表格?让我知道我是否应该,我很乐意发布它们。
编辑:以上问题中使用的表格......
TABLE bb_shopper (
idShopper number(4),
FirstName varchar2(15),
LastName varchar2(20),
Address varchar2(40),
City varchar2(20),
State char(2),
ZipCode varchar2(15),
Phone varchar2(10),
Fax varchar2(10),
Email varchar2(25),
UserName varchar2(8),
Password varchar2(8),
Cookie number(4) DEFAULT 0,
dtEntered date DEFAULT SYSDATE,
Promo char(1),
CONSTRAINT shopper_id_pk PRIMARY KEY(idShopper)
);
TABLE bb_product (
idProduct number(2) ,
ProductName varchar2(25) ,
Description varchar2(100) ,
ProductImage varchar2(25),
Price number(6,2),
Active number(1),
Type char(1),
stock number(5,1),
ordered number(3),
reorder number(3),
idDepartment number(2),
CONSTRAINT prod_id_pk PRIMARY KEY(idProduct)
);