I am trying to solve a problem in PL/SQL, but I am new to the language. I decided to solve it as I would solve it in another language, and so I learned something about how SQL declares and utilizes arrays in this thread:
Oracle PL/SQL - How to create a simple array variable?
I followed that example, but my code doesn't run. The error message is unhelpful. In particular it references line 21 whereas my code block begins on line 54. Here it is, in case it makes sense by error code, somehow:
ORA-06550: line 21, column 7: PLS-00103: Encountered the symbol "IN" when expecting one of the following: := . ( @ % ; 06550. 00000 - "line %s, column %s:\n%s" *Cause: Usually a PL/SQL compilation error.
And here is my code block. I am sure I made a bunch of mistakes since I am learning by code example here. If you could please point out any syntax or other errors I would very much appreciate it. Thank you
declare
vISBNa books.ISBN%type := '1059831198';
vISBNb books.ISBN%type := '0401140733';
vISBNc books.ISBN%type := '4981341710';
vISBNd books.ISBN%type := '8843172113';
vCATEGORYtemp books.CATEGORY%type;
vRETAILtemp books.RETAIL%type;
type arry is varray(4) of books.ISBN%type;
array arry := arry(vISBNa, vISBNb, vISBNc, vISBNd);
begin
for i in 1..array.count loop
select category
into vCATEGORYtemp
from books
where ISBN = i;
select retail
into vRETAILtemp
from books
where ISBN = i;
IF vCATEGORYtemp = 'COMPUTER' THEN
vRETAILtemp := vRETAILtemp * 0.7;
ELSIF vCATEGORYtemp = 'FITNESS' THEN
vRETAILtemp := vRETAILtemp * 0.6;
ELSIF vCATEGORYtemp = 'BUSINESS' THEN
vRETAILtemp := vRETAILtemp * 0.8;
ELSE
vRETAILtemp := vRETAILtemp * 0.9;
END IF;
dbms_output.put_line(vRETAILtemp);
end loop;
end;